git for-each-ref https://git-scm.com/docs/git-for-each-ref告诉你每个 ref 默认是什么,它的 id 和它的类型。要将其限制为仅标签,请执行以下操作git for-each-ref refs/tags
.
[T]输出具有三个字段:对象的哈希、对象的类型以及引用该对象的 refs/tags 中的名称。所谓的“轻量级”标签是 refs/tags 中引用某个内容的名称commit
1 对象。 “带注释”标签是 refs/tags 中的名称,指的是tag
object.
- 所罗门·斯洛 https://stackoverflow.com/users/801894/solomon-slow(在评论中)
这是一个例子:
$ git for-each-ref refs/tags
902fa933e4a9d018574cbb7b5783a130338b47b8 commit refs/tags/v1.0-light
1f486472ccac3250c19235d843d196a3a7fbd78b tag refs/tags/v1.1-annot
fd3cf147ac6b0bb9da13ae2fb2b73122b919a036 commit refs/tags/v1.2-light
具有某种格式:
$ git for-each-ref \
--format="%(if:equals=tag)%(objecttype)%(then)a %(else)%(if:equals=blob)%(objecttype)%(then)b %(else) %(end)%(end)%(align:20,right)%(refname:short)%09%(objectname:short)%(end)%09%(if:equals=tag)%(objecttype)%(then)@%(object) %(contents:subject)%(else)%(end)" \
--sort=taggerdate \
refs/tags
v1.2-light fd3cf14
b forsam 633de05
a v1.1-annot 1f48647 @1e25186bcf26d260754b6ebf6b236e92eeadc69b annotation comment
v1.0-light 902fa93
要仅对一位参考执行此操作,您可以使用git cat-file https://git-scm.com/docs/git-cat-file -t
在本地参考上,继续示例:
$ git cat-file -t v1.0-light
commit
$ git cat-file -t v1.1-annot
tag
¹ tags can refer to any Git object, if you want a buddy to fetch just one file and your repo's got a git server, you can git tag forsam :that.file
and Sam can fetch it and show it. Most of the convenience commands don't know what to do with tagged blobs or trees, but the core commands like update-index and such do