我在存储库中有一堆没有注释的标记,我想弄清楚它们指向哪个提交。是否有一个命令只列出标签和它们的提交sha ?检查标签和查看头部似乎有点太费力对我来说。
更新
在检查完响应后,我意识到我实际上想要的只是查看标记之前的历史记录,对于这一点git log <tagname>就足够了。
标记为answer的答案对于获取标记及其提交的列表很有用,这就是我所要求的。通过一点shell hack,我相信可以将这些转换为SHA+Commit消息。
我在存储库中有一堆没有注释的标记,我想弄清楚它们指向哪个提交。是否有一个命令只列出标签和它们的提交sha ?检查标签和查看头部似乎有点太费力对我来说。
更新
在检查完响应后,我意识到我实际上想要的只是查看标记之前的历史记录,对于这一点git log <tagname>就足够了。
标记为answer的答案对于获取标记及其提交的列表很有用,这就是我所要求的。通过一点shell hack,我相信可以将这些转换为SHA+Commit消息。
当前回答
我也想知道“正确”的方法,但同时,你可以这样做:
git show mytag | head -1
其他回答
这里没有显示文件名,但至少您可以了解存储库。
cat .git/refs/tags/*
该目录中的每个文件都包含一个指向提交的提交SHA。
警告:这只适用于Unannotated标签,因此,它是更安全的使用已接受的答案,在一般情况下工作https://stackoverflow.com/a/1862542/1586965
git show-ref --tags
例如,git show-ref——abbrev=7——tags会显示如下内容:
f727215 refs/tags/v2.16.0
56072ac refs/tags/v2.17.0
b670805 refs/tags/v2.17.1
250ed01 refs/tags/v2.17.2
只需使用git show <tag>
但是,它也转储提交差异。要忽略这些差异,使用git log -1 <tag>。(感谢@DolphinDream和@demisx !)
来自Igor Zevaka:
总结
由于大约有4个几乎同样可接受但不同的答案,我将总结所有不同的方法来皮肤标签。
git rev-list -1 $TAG (answer). git rev-list outputs the commits that lead up to the $TAG similar to git log but only showing the SHA1 of the commit. The -1 limits the output to the commit it points at. git show-ref --tags (answer) will show all tags (local and fetched from remote) and their SHA1s. git show-ref $TAG (answer) will show the tag and its path along with the SHA1. git rev-parse $TAG (answer) will show the SHA1 of an unannotated tag. git rev-parse --verify $TAG^{commit} (answer) will show a SHA1 of both annotated and unannotated tags. On Windows use git rev-parse --verify %TAG%^^^^{commit} (four hats). cat .git/refs/tags/* or cat .git/packed-refs (answer) depending on whether or not the tag is local or fetched from remote.
从git邮件列表中,可以通过自动对带注释的标签解引用来获得标签的提交哈希列表:
git for-each-ref --format='%(if)%(*objectname)%(then)%(*objectname)%(else)%(objectname)%(end) %(refname)' refs/tags