George Sovetov George Sovetov - 10 days ago 7
Git Question

Git: how do I find tags pointing to specific revision?

Given some revision, say

HEAD^^^
, I need to find tags pointing to it.

I can do that with
git show-ref --tags | grep $(git rev-parse $REV) | awk '{print $2}'
.

Is there special command for it? (That works on Windows too.) Maybe there is even back reference mechanism in Git...

Answer

EDIT

To list tags pointing to a given commit use the following command:

git tag --points-at commit

git tag --contains isn't a correct answer to this question, since it also includes later tags from which the specified revision is reachable.


git tag -l --contains $REV

From git tag documentation:

-l <pattern>, --list <pattern>

List tags with names that match the given pattern (or all if no pattern is given).

--contains [<commit>]

Only list tags which contain the specified commit (HEAD if not specified).