Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

git-tag

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.

like image 402
Igor Zevaka Avatar asked Dec 07 '09 19:12

Igor Zevaka


People also ask

How do I view a tag commit?

Find Latest Git Tag Available In order to find the latest Git tag available on your repository, you have to use the “git describe” command with the “–tags” option. This way, you will be presented with the tag that is associated with the latest commit of your current checked out branch.

How do I find the commit list?

On GitHub.com, you can access your project history by selecting the commit button from the code tab on your project. Locally, you can use git log . The git log command enables you to display a list of all of the commits on your current branch. By default, the git log command presents a lot of information all at once.

Can you see who created a tag in git?

They're just refs in the refs/tags namespace, but they point to commits instead of tag objects. This means there are no details to show.


1 Answers

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 

NOTE This works for both Annotated and Unannotated tags

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

[alias]   tagcommit = rev-list -n 1 

And then call it with:

$ git tagcommit $TAG 

Possible pitfall: if you have a local checkout or a branch of the same tag name, this solution might get you "warning: refname 'myTag' is ambiguous". In that case, try increasing specificity, e.g.:

$ git rev-list -n 1 tags/$TAG 
like image 72
mipadi Avatar answered Sep 29 '22 03:09

mipadi