Git标签仅适用于当前分支吗? [英] Do Git tags only apply to the current branch?

查看:80
本文介绍了Git标签仅适用于当前分支吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用具有多个分支的存储库.

I'm currently working with a repository that has multiple branches.

创建标签时,该标签是否指向then-current分支?

When I create a tag, does that tag refer to the then-current branch?

换句话说:每当我创建标签时,是否都需要切换到所需的分支并在该分支内进行标签,以便该标签在那个时间点指向该分支?

In other words: Whenever I create a tag, do I need to switch to the desired branch and tag inside that branch so that the tag refers to that branch at that point in time?

推荐答案

如果您通过例如创建标签

If you create a tag by e.g.

git tag v1.0

标签将引用您当前所在分支的最新提交.您可以更改分支并在那里创建标签.

the tag will refer to the most recent commit of the branch you are currently on. You can change branch and create a tag there.

您也可以在标记时引用另一个分支

You can also just refer to the other branch while tagging,

git tag v1.0 name_of_other_branch

这将创建标记到另一个分支的最新提交.

which will create the tag to the most recent commit of the other branch.

或者您可以通过直接引用某些提交的SHA1,将标签放置在任何位置,无论是哪个分支

Or you can just put the tag anywhere, no matter which branch, by directly referencing to the SHA1 of some commit

git tag v1.0 <sha1>

这篇关于Git标签仅适用于当前分支吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆