获取标签的提交哈希 [英] Get the commit hash for a tag
问题描述
它与>使git show有关以机器可解析的格式显示信息,但是我已经厌倦了这样一个事实,我现在必须做很多解析才能获取提交哈希.
It is related to Making git show to show information in a machine parseable format but I am getting tired of the fact that I now have to do a lot of parsing to get the commit hash.
有人可以给我一个命令,该命令将打印给定git标记的提交哈希(仅提交哈希)标签吗?我希望
Can someone give me a command that will print the commit hash (and only the commit hash) tag for a given git tag? I was hoping
git show mylabel --pretty=format:"%H" --quiet
请只打印我的提交编号,但它会显示
Would just print me my commit # but it says
tag mylabel
Tagger: user <user@x.com>
Some comment
446a52cb4aff90d0626b8232aba8c40235c16245
我期望输出只有一行,但是我现在必须解析最后一行?
I was expecting one line of output with just the commit line but I now have to parse for the last line?
推荐答案
git log -1 --format=format:"%H" mylabel
实际上,更好的解决方案是:
Actually a better solution would be :
git show-ref -s mylabel
EDIT之二:如注释中所述,请注意带注释的提交(属于它们自己的对象).要获得更通用的解决方案,请阅读@michas答案.
EDIT bis: As mentioned in the comments, be careful with annotated commits (which are objects of their own). To have a more generic solution, read @michas answer.
当您执行git show-ref -d mylabel
时,您会看到区别.
You can see the difference when you do a git show-ref -d mylabel
.
资源:
这篇关于获取标签的提交哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!