Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
504 views
in Technique[技术] by (71.8m points)

logging - Git Tag list, display commit sha1 hashes

so the git tag command lists the current git tags

tag1
tag2

git tag -n prints tag's message

tag1  blah blah
tag2  blah blah

What's the best way to get the hash of tag1 & tag2 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To get git tags with the SHA1 hash of the Tag object, you can run:

git show-ref --tags

The output will then look something like:

0e76920bea4381cfc676825f3143fdd5fcf8c21f refs/tags/1.0.0
5ce9639ead3a54bd1cc062963804e5bcfcfe1e83 refs/tags/1.1.0
591eceaf92f99f69ea402c4ca639605e60963ee6 refs/tags/1.2.0
40414f41d0fb89f7a0d2f17736a906943c05acc9 refs/tags/1.3.0

Each line is the SHA1 hash of the tag, followed by the tag name prefixed with refs/tags/.

If you want the SHA1 hash of the commit, instead of the tag object, you can run:

git show-ref --tags -d

This will produce output like:

0e76920bea4381cfc676825f3143fdd5fcf8c21f refs/tags/1.0.0
3e233dd8080617685992dc6346f739a6f6396aae refs/tags/1.0.0^{}
5ce9639ead3a54bd1cc062963804e5bcfcfe1e83 refs/tags/1.1.0
09173980152a7ed63d455829553448ece76c6fdc refs/tags/1.1.0^{}
591eceaf92f99f69ea402c4ca639605e60963ee6 refs/tags/1.2.0
56d803caaa8a93a040b7be0b8a36abdc4ce8c509 refs/tags/1.2.0^{}
40414f41d0fb89f7a0d2f17736a906943c05acc9 refs/tags/1.3.0
1bdf628a70fda7a0d840c52f3abce54b1c6b0130 refs/tags/1.3.0^{}

The lines ending with ^{} start with the SHA1 hash of the actual commit that the tag points to.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...