git标签是否适用于所有分支? [英] Do git tags apply to all branches?

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

问题描述


$ b $我用git标记弄湿了自己的脚,但我之前的背景是在Subversion中,标签实际上只是复制品,而不是真正的标签。 b

如果我向git repo添加标签,它是否应用于所有分支或仅应用于当前分支?



例如,如果我当前有这些分支( git branch -v ):

  * master deadbeef我的主人评论
dev baddfeed我的def头评论

目前签出的分支是master,你可以看到。现在假设我 git tag -a TAGNAME TAGNAME 只适用于 deadbeef baddfeed (dev分支)?

例如,说我然后在签出标签之前切换到dev分支(即,不是标签创建的分支):

  git checkout dev 
git checkout TAGNAME

然后我最终签出 baddfeed 或者标记签出(第二行)将我切换回主分支(创建标记的位置)并给我签出 deadbeef
(或者第三种选择,是我对创建和恢复标记的理解是否太过瑕疵或过于简单,答案就如同这两个选项之一一样简单)?

另外,如果我使用轻量级标记( git tag TAGNAME )而不是带注释的标记,那么问题的答案是否会更改?

解决方案

假设您位于分支 myBranch 中。你创建了一个名为 myTag

的标签
$ b

  ----- A ----- -----乙ç----- ----- dħ------- -----我> master 
\
\
\ --- E ---- F ----- G -----> myBranch
|
myTag

标签只会在 myBranch 分支。我也和CVS一起工作过,它也标记修订版本,并非所有分支(但在CVS分支中都是特殊标签)。我不这么认为。

如果您签出 myTag ,您将在提交 G 的例子。您不能在不同分支上创建具有相同名称的标签。如果你这样做,你会移动标签。



与此相关的注释标签没有区别。



<注意:检出标签时,最终会出现分离头部模式。除非您从检出标签开始创建另一个分支,否则您的更改将会丢失。


I'm getting my feet wet with git tagging, but my previous background is in Subversion, where "tags" were really just copies, not "real" tags...

If I add a tag to a git repo, is it applied to all branches or only the current one?

For example, if I currently have these branches (git branch -v):

* master deadbeef My master head comment
  dev    baddfeed My def head comment

And the currently checked out branch is master, as you can see. Now suppose I git tag -a TAGNAME, does TAGNAME apply only to deadbeef (master branch) or to baddfeed (dev branch) as well?

e.g., Say I subsequently switch to the dev branch (i.e., not the branch the tag was created on) before checking out the tag:

git checkout dev
git checkout TAGNAME

Do I then end up with a checkout of baddfeed or will the tag checkout (second line) switch me back to the master branch (where the tag was created) and give me a checkout of deadbeef? (Or third option, is my understanding of creating and restoring tags too flawed or too simplistic for the answer to be as simple as one of those two options?)

Also, does the answer to my question change any if I use a lightweight tag (git tag TAGNAME) instead of an annotated tag?

解决方案

Let's say you are in branch myBranch. And you create a tag called myTag

-----A-----B-----C-----D-----H-------I-----> master
                       \
                        \
                         \---E----F-----G-----> myBranch
                                        |
                                        myTag

The tag will be only on the commit object of the myBranch branch. I've worked with CVS too, and it tags revisions too, not all branches (but in CVS branches are special tags). I don't think.

If you checkout myTag, you will be in the commit G of the example. You can't create tags with the same name on differente branches. If you do it, you will move the tag.

There's no difference for an annotated tag related to this.

Note: when checking out tags, you end up with "detached HEAD" mode. Your changes will be lost unless you create another branch starting from the tag checked out.

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

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