I have a bunch of unannotated tags in the repository and I want to work out which commit they point to. Is there a command that that will just list the tags and their commit SHAs? Checking out the tag and looking at the HEAD seems a bit too laborious to me.
Update
I realized after I went through the responses that what I actually wanted was to simply look at the history leading up to the tag, for which git log <tagname>
is sufficient.
The answer that is marked as answer is useful for getting a list of tags and their commits, which is what I asked. With a bit of shell hackery I'm sure it's possible to transform those into SHA+Commit message.
This doesn't show the filenames, but at least you get a feel of the repository.
Each file in that directory contains a commit SHA pointing to a commit.
You could as well get more easy-to-interpret picture of where tags point to using
and then scroll to the tag you're looking for via
/
.More compact view (
--pretty=oneline
) plus all heads (-a
) could also help:Looks a bit terrifying, but could also be aliased in
~/.gitconfig
if necessary.From Igor Zevaka:
Summary
Since there are about 4 almost equally acceptable yet different answers I will summarise all the different ways to skin a tag.
git rev-list -1 $TAG
(answer).git rev-list
outputs the commits that lead up to the$TAG
similar togit 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 usegit rev-parse --verify %TAG%^^^^{commit}
(four hats).cat .git/refs/tags/*
orcat .git/packed-refs
(answer) depending on whether or not the tag is local or fetched from remote.In order to get the sha/hash of the commit that a tag refers to (not the sha of the tag):
git rev-list -1 <tag>
Just use
git show <tag>
However, it also dumps commit diffs. To omit those diffs, use
git log -1 <tag>
. (Thanks to @DolphinDream and @demisx !)How about this:
OR