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 ?
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 ?
The
git tag
command is underdeveloped. A lot is desired but missing in it, like full tag details and tags in the commit history order.I like this instead, which gives exactly what I want but can't get from
git tag
:This gives a very nice color-coded view of the tags in the reverse chronological order (as it would be in the full log). That way, not only do you see the tags, you will also see the abbreviated hashes and the commit messages of the tag commits.
I have aliased it to
git t
andgit tags
as follows:Note: I had to use bash redirection for
git t
as Git doesn't support calling an alias from another alias (which is a bummer).If you want to see the commit date and time, try:
You can use other date formats in the
--date
option as well as fully control the output to match your unique taste in the--pretty
option. Both options are well-documented in the git-log Documentation.The tags have to be signed and/or messaged. Lightweight tags don't have SHA1 objects and are just refs. Otherwise try
git show
.To get the SHA1 referred to by any sort of ref (branch, tag...) use
git rev-parse
: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!
This gives a list of all commits for tags. Annotated tags are dereferenced. Send thanks here.
How about this?
I had a similar question, but wanted the hash of (several) specific tags. I found that "show-ref" will take a list of tags, so this does the job:
However, some experimentation with "git show" resulted in this command:
Since I'm much more familiar with using "show" than "show-ref", I find the latter easier to remember and more helpful too.
See also the nice summary in How to tell which commit a tag points to in Git?.