git 如何在git中列出指向特定提交的所有标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4545370/
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
How to list all tags pointing to a specific commit in git
提问by Zitrax
I have seen the commands git describe
and git-name-rev
but I have not managed to get them to list more than one tag.
我已经看到了这些命令git describe
,git-name-rev
但我还没有设法让它们列出多个标签。
Example: I have the sha1 48eb354 and I know the tags A and B point to it. So I want a git command git {something} 48eb354
that produce output similar to "A, B". I am not interested in knowing references relative other tags or branches just exact matches for tags.
示例:我有 sha1 48eb354 并且我知道标签 A 和 B 指向它。所以我想要一个git {something} 48eb354
产生类似于“A,B”的输出的 git 命令。我对知道与其他标签相关的引用或分支只是标签的完全匹配不感兴趣。
采纳答案by max
git show-ref --tags -d | grep ^48eb354 | sed -e 's,.* refs/tags/,,' -e 's/\^{}//'
git show-ref --tags -d | grep ^48eb354 | sed -e 's,.* refs/tags/,,' -e 's/\^{}//'
should work for both lightweight and annotated tags.
应该适用于轻量级和带注释的标签。
回答by user2159398
git tag --points-at HEAD
git tag --points-at HEAD
Shows all tags at HEAD, you can also substitute HEAD with any sha1 id.
在 HEAD 显示所有标签,您也可以用任何 sha1 id 替换 HEAD。
回答by yorammi
You can use:
您可以使用:
git tag --contains <commit>
that shows all tags at certain commit. It can be used instead of:
显示特定提交的所有标签。它可以用来代替:
git tag --points-at HEAD
that is available only from 1.7.10.
仅从 1.7.10 开始可用。
回答by Aristotle Pagaltzis
git for-each-ref --format='%(objectname) %(refname:short)' refs/tags/ |
grep ^$commit_id |
cut -d' ' -f2
Pity it can't be done more easily. Another flag on git tag
to include commit IDs could express that git for-each-ref
invocation naturally.
可惜它不能更容易做到。git tag
包含提交 ID 的另一个标志可以git for-each-ref
自然地表达该调用。
回答by Sylvain Defresne
The following command does the job, but directly parse the content of the .git directory and thus may break if the git repository format change.
以下命令可以完成这项工作,但直接解析 .git 目录的内容,因此如果 git 存储库格式更改,则可能会中断。
grep -l -r -e '^48eb354' .git/refs/tags|sed -e 's,.*/,,'