Git Tag list, display commit sha1 hashes

后端 未结 8 1138
无人共我
无人共我 2020-12-12 17:56

so the git tag command lists the current git tags

tag1
tag2

git tag -n prints tag\'s message

tag1         


        
8条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-12 18:26

    To get the SHA1 referred to by any sort of ref (branch, tag...) use git rev-parse:

    git rev-parse tag1^0 tag2^0
    

    It will print only the full SHA1s, on separate lines. The ^0 suffix is a special syntax, to ensure that this will print the SHA1 of the commit pointed to by the tag, whether it's annotated or not. (Annotated tags are objects in their own right, which contain a pointer to a commit along with metadata. If you do know a tag is annotated, and want the tag's SHA1, simply leave off the ^0.)

    Of course, you shouldn't often need to do this, since any Git command that would accept an SHA1 should also accept a tag!

提交回复
热议问题