tags:

views:

130

answers:

2

Is there a way to get the tag associated with a commit number in Git?

For releases I usually tag with something like v1.1.0. During my build script I am creating a fwVersion.c file that contains the current git info. Currently, I have commit, and branch info in the file, but I would like to add the tag.

Is this possible?

Thanks

+1  A: 

RTFM my friend ;)

git tag --contains <commit>
dharga
This will list all of the tags which contain the given commit (i.e. tags which point to children of the given commit), so it's not necessarily going to give a single tag for a given commit or any information about which tag is closest, unless the list only contains a single commit.
Charles Bailey
As Charles Bailey says above, that's not exactly what I'm looking for. Maybe you should RTFM :)
wes
Well, sorry for the wrong answer. When I checked it seemed to do what you were asking for. I did RTFM, I was just solving the wrong problem. Hope Bailey offered a solution that helps you out.
dharga
+3  A: 

Check the documentation for git describe. It finds the nearest tag to a given commit (that is a tag which points to an ancestor of the commit) and describes that commit in terms of the tag.

If you only want to know if the commit is pointed to by a tag then you can check the output of:

git describe --exact-match <commit-id>
Charles Bailey
This is perfect, thanks!!
wes