我在存储库中有一堆没有注释的标记,我想弄清楚它们指向哪个提交。是否有一个命令只列出标签和它们的提交sha ?检查标签和查看头部似乎有点太费力对我来说。
更新
在检查完响应后,我意识到我实际上想要的只是查看标记之前的历史记录,对于这一点git log <tagname>就足够了。
标记为answer的答案对于获取标记及其提交的列表很有用,这就是我所要求的。通过一点shell hack,我相信可以将这些转换为SHA+Commit消息。
我在存储库中有一堆没有注释的标记,我想弄清楚它们指向哪个提交。是否有一个命令只列出标签和它们的提交sha ?检查标签和查看头部似乎有点太费力对我来说。
更新
在检查完响应后,我意识到我实际上想要的只是查看标记之前的历史记录,对于这一点git log <tagname>就足够了。
标记为answer的答案对于获取标记及其提交的列表很有用,这就是我所要求的。通过一点shell hack,我相信可以将这些转换为SHA+Commit消息。
当前回答
来自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.
其他回答
如果您想查看标记SOMETAG(标记器,日期等)的详细信息,它所指向的提交的哈希值和一些关于提交的信息,但没有完整的差异,请尝试
git show --name-status SOMETAG
示例输出:
tag SOMETAG
Tagger: ....
Date: Thu Jan 26 17:40:53 2017 +0100
.... tag message .......
commit 9f00ce27c924c7e972e96be7392918b826a3fad9
Author: .............
Date: Thu Jan 26 17:38:35 2017 +0100
.... commit message .......
..... list of changed files with their change-status (like git log --name-status) .....
这里没有显示文件名,但至少您可以了解存储库。
cat .git/refs/tags/*
该目录中的每个文件都包含一个指向提交的提交SHA。
format选项可用于显示标记散列和提交散列,并用于区分轻量级标记和带注释的标记。
git tag --format="%(color:bold cyan)== %(refname:short) ==%(if)%(object)%(then)%0aTag Hash: %(objectname)%0aTag Date: %(taggerdate:iso-local)%0a Commit: %(object) %0a%0a%(contents)%(else)%0a(lightweight tag)%0a Commit: %(objectname)%(end)%0a"
输出类似于:
== b2lightweight ==
(lightweight tag)
Commit: 0450fae4352dbbbf088419757eda32711316a02e
== c3_annotated ==
Tag Hash: 19961d8678a09a319a9d6c398c79f27cc23d610c
Tag Date: 2021-08-06 15:18:48 -0600
Commit: 85be6e80c109ce44d78f0ca0da8e1ec53817b24c
This is my tag message.
It has multiple lines.
Another line.
要定义为git别名,你可以使用git config——global -e编辑全局git配置,并添加以下内容:
[alias]
tag-verbose = tag --format='%(color:bold cyan)== %(refname:short) ==%(if)%(object)%(then)%0aTag Hash: %(objectname)%0aTag Date: %(taggerdate:iso-local)%0a Commit: %(object) %0a%0a%(contents)%(else)%0a(lightweight tag)%0a Commit: %(objectname)%(end)%0a'
别名仍然允许过滤,例如。
C:\playground>git tag-verbose -l *b2*
== b2lightweight ==
(lightweight tag)
Commit: 0450fae4352dbbbf088419757eda32711316a02e
有关——format选项的更多信息,请参阅git help For -each-ref下的“字段名称”部分。(git帮助标签声明“格式与git-for-each-ref相同”)
简短的后git -2回答
我知道这个问题已经提出很久了。CB Bailey的答案是100%正确的:git show-ref——tags——abbrev
我更喜欢这个,因为它使用了git标签:
git tag --list --format '%(refname:short) %(objectname:short)'
简单。短。
PS用这个命令将它别名为git标签列表:
git config --global alias.taglist "tag --list --format '%(refname:short) %(objectname:short)'"
您还可以获得更容易理解的标签指向何处使用的图片
git log --graph |git name-rev --stdin --tags |less
然后通过/滚动到您正在寻找的标记。
更紧凑的视图(——pretty=oneline)加上所有头像(-a)也可以帮助:
git log -a --pretty=oneline --graph |git name-rev --stdin --tags |less
看起来有点可怕,但也可以在~/中别名。Gitconfig(如果需要的话)。
~/.gitconfig
[alias]
ls-tags = !git log -a --pretty=oneline --graph |git name-rev --stdin --tags |less