Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

tags

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.

like image 662
Zitrax Avatar asked Dec 28 '10 10:12

Zitrax


People also ask

How will you list your tags in git?

List Local Git Tags. In order to list Git tags, you have to use the “git tag” command with no arguments. You can also execute “git tag” with the “-n” option in order to have an extensive description of your tag list. Optionally, you can choose to specify a tag pattern with the “-l” option followed by the tag pattern.

How can you display a list of files added in a specific commit?

To reduce the information and show only names of the files which committed, you simply can add --name-only or --name-status flag... These flags just show you the file names which are different from previous commits as you want...

How do you check if a commit is tagged?

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. In newer versions, git describe --tags --abbrev=0 REV will be useful when you don't want the junk on the tag.

Which command is used to give tags to the specified commit?

In order to create a Git tag for a specific commit, use the “git tag” command with the tag name and the commit SHA for the tag to be created.


4 Answers

git tag --points-at HEAD

Shows all tags at HEAD, you can also substitute HEAD with any sha1 id.

like image 146
user2159398 Avatar answered Oct 23 '22 13:10

user2159398


You can use:

git tag --contains <commit>

that shows all tags at certain commit. It can be used instead of:

git tag --points-at HEAD

that is available only from 1.7.10.

like image 40
yorammi Avatar answered Oct 23 '22 13:10

yorammi


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

should work for both lightweight and annotated tags.

like image 49
max Avatar answered Oct 23 '22 13:10

max


(Edit: This answer was written long before git tag had the --points-at switch – which is what you would use nowadays.)

git for-each-ref --format='%(objectname) %(refname:short)' refs/tags/ |
  grep ^$commit_id |
    cut -d' ' -f2

Pity it can’t be done more easily. Another flag on git tag to include commit IDs could express that git for-each-ref invocation naturally.

like image 6
Aristotle Pagaltzis Avatar answered Oct 23 '22 11:10

Aristotle Pagaltzis