Git:如何找出标签在哪个分支上?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15806448/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 15:55:14  来源:igfitidea点击:

Git: How to find out on which branch a tag is?

gittagsbranch

提问by Viacheslav Kondratiuk

I'm currently busy with a project with a lot of branches and I have a tag for last changes which where done on one of the branches. But it's not clear for me on which branch this tag is.

我目前正忙于一个有很多分支的项目,我有一个标签,用于在其中一个分支上完成的最后更改。但是我不清楚这个标签在哪个分支上。

How to find out on which branch a tag is?

如何找出标签在哪个分支上?

回答by VonC

Even shorter:

更短:

git branch --contains tags/<tag>

(it works for any tree-ish reference)

(它适用于任何树状参考)



If you can find which commit a tag refers to:

如果你能找到标签所指的提交

 git rev-parse --verify tags/<tag>^{commit}
 # or, shorter:
 git rev-parse tags/<tag>~0

Then you can find which branch contain that commit.

然后你可以找到哪个分支包含那个 commit

git branch --contains <commit>


As commentedbelow by user3356885, for the fetched branches (branches in remotes namespace)

正如user3356885在下面评论那样,对于获取的分支(远程命名空间中的分支)

git branch -a --contains tags/<tag>
git branch -a --contains <commit>

回答by david1977

If "git branch --contains " does nothing, be sure that you are including all branches, both remote and local branches:

如果“git branch --contains”什么都不做,请确保包含所有分支,包括远程和本地分支:

git branch -a --contains <tag>

From the git help:

Specific git-branch actions: -a, --all list both remote-tracking and local branches

从 git 帮助:

特定的 git-branch 操作:-a, --all 列出远程跟踪和本地分支

回答by Peter Jaric

git branch --contains tag

does nothing for me, but I found my solution to this problem in git gui.

对我没有任何作用,但我在git gui 中找到了解决此问题的方法。

Start it like this:

像这样开始:

git gui

(On my Ubuntu I had to install it first with sudo apt-get install git-gui.)

(在我的 Ubuntu 上,我必须先安装它sudo apt-get install git-gui。)

Then I selected the menu item Repository -> Visualize All Branch History. In the resulting window I then selected the menu item File -> List References.

然后我选择了菜单项Repository -> Visualize All Branch History。在结果窗口中,我选择了菜单项File -> List References

Another window popped up, listing all my tags (and other references). These are clickable and after clicking one of them I just had to check the bottom left frame for the list of branches. Like this:

另一个窗口弹出,列出我所有的标签(和其他参考)。这些是可点击的,点击其中一个后,我只需要检查左下角的框架以获取分支列表。像这样:

Parent: somesha (message)
Parent: someothersha (another message)
Child:  anothersha (yet another message)
Branches: branch1, master, remotes/origin/branch2, remotes/upstream/branch1, etc
Follows: v1.1.2
Precedes: v1.1.4

回答by arpieb

In regards to @VonC's comment about finding the commit referenced by a tag, just use:

关于@VonC 关于查找标记引用的提交的评论,只需使用:

git show <tag>

Since a tag is tied to a specific commit, it can be used to show that commit - which will give you the full commit details.

由于标签与特定提交相关联,因此可用于显示该提交 - 这将为您提供完整的提交详细信息。

回答by René H?hle

With a Tag you mark a reference. So when you are on a dev branch and Tag this state. Your tag is on the actual reference. So in this case you can look to gitkor another tool where the tree is shown. There you can see on which reference the Tag is.

使用标签,您可以标记参考。因此,当您在开发分支上并标记此状态时。您的标签在实际参考中。因此,在这种情况下,您可以查看gitk或其他显示树的工具。在那里你可以看到标签是在哪个引用上的。

git: Is there something like per-branch tags?
http://git-scm.com/book/en/Git-Basics-Tagging

git:有没有像每个分支标签这样的东西?
http://git-scm.com/book/en/Git-Basics-Tagging

Here is a good explanation.

这是一个很好的解释。

回答by ttfreeman

A tag is always referring to commit number. Using that tag number you can find the branch from which the tag was placed using this:

标签总是指提交编号。使用该标签编号,您可以使用以下命令找到放置标签的分支:

git for-each-ref | grep ${commit_num} | grep origin | sed "s/.*\///"