Search code examples
gittags

How to list all tags pointing to a specific commit in git


I have seen the commands git describe and git-name-rev but I have not managed to get them to list more than one tag.

Example: I have the sha1 48eb354 and I know the tags A and B point to it. So I want a git command git {something} 48eb354 that produce output similar to "A, B". I am not interested in knowing references relative other tags or branches just exact matches for tags.


Solution

  • git show-ref --tags -d | grep ^48eb354 | sed -e 's,.* refs/tags/,,' -e 's/\^{}//'

    should work for both lightweight and annotated tags.