Igor Zevaka Igor Zevaka - 5 months ago 29
Git Question

How to tell which commit a tag points to in Git?

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 labourious to me.


I realised 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.


One way to do this would be with git rev-list. The following will output the commit to which a tag points:

$ git rev-list -n 1 $TAG

You could add it as an alias in ~/.gitconfig if you use it a lot:

  tagcommit = rev-list -n 1

And then call it with:

$ git tagcommit $TAG