Find tag information for this commit

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

For releases, I usually mark something like v1.1.0. During my build script I create a fwVersion.c file containing the current git information. I currently have the commit and branch information in the file, but I would like to add a tag.

Is it possible?

+56
git
Sep 24 '09 at 20:58
source share
5 answers

Check out the documentation on git describe . It finds the closest tag for the given commit (i.e., the Tag pointing to the commit's ancestor) and describes this commit in terms of the tag.

If you only want to know what the tagging indicates, you can check the output:

 git describe --exact-match <commit-id> 
+71
Sep 24 '09 at 21:07
source share

If you want, this is the first tag containing commit, and then:

 git describe --contains <commit> 

gives a better IMO answer. If you have more frequent tags than using the git --contains "tag on an old commit in a large repository, it may take some time and you will get all the tags that contain that commit.

This form of git description is very fast and gives you one output value, which is the first tag containing the commit and how far back your commit is.

+46
Sep 26 2018-11-21T00:
source share

You can find this information in the manual.

 git tag --contains <commit> 
+12
Sep 24 '09 at 21:06
source share

Sorry, I didnโ€™t know how to simply add a comment, so I'm sending an answer ... I found a combo of both vertices to give me what I wanted like this:

 git describe --tags --exact-match <commit-id> 

This gives you tags (tags) that are ONLY for this commit and for those who have no annotation. Useful if you want to find tags and not worry about removing formatting (e.g. for Jenkins).

eg. $ git describe --tags --exact-match head~2

Gives you:

 $ ReleaseBeta 
+6
Jan 25 '13 at 9:01
source share

How about this?

git tag --points-at <commit-id>

It gives you all the tags that the given commit has (while git describe gives only one), and does not include tags in git tag --contains streams (e.g. git tag --contains ).

+5
Nov 20 '15 at 11:07
source share



All Articles