Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get tags on current commit

Tags:

git

I have a repository which has multiple tags on the same commit. For example:

commit #3 <--- TAG1 / TAG2 / TAG3    |  commit #2 <--- TAG4/ TAG5    |  commit #1 <--- TAG6/ TAG7 

I'd like to find out what tags are on a particular commit. For example, if I check commit 1, I'd like to get tag 6 and tag 7.

I have tried:

git checkout <commit 1>  git tag --contains 

which displayed tags 1-7.

git checkout <commit 1> git describe --tags HEAD 

displayed tag 6 only.

What is the proper way to do this in Git?

like image 677
Shawn Avatar asked Feb 24 '10 06:02

Shawn


People also ask

How do I find my current tag?

Find Latest Git Tag Available In order to find the latest Git tag available on your repository, you have to use the “git describe” command with the “–tags” option. This way, you will be presented with the tag that is associated with the latest commit of your current checked out branch.

How do I fetch all tags?

To fetch tags from your remote repository, use “git fetch” with the “–all” and the “–tags” options. Let's say for example that you have a tag named “v1. 0” that you want to check out in a branch named “release”. Using this command, you have successfully checked out the “v1.

Which command will list all tags in current branch in git?

You can list all existing tags git tag or you could filter the list with git tag -l 'v1.


1 Answers

For completion (thanks to Ciro Santili answer), git tag has got the option --points-at that does exactly what OP is asking.

git tag --points-at HEAD 

It does not have the effect of also listing the tags put on forward commits (as Jonathan Hartley stated in his comment regarding git tag --contains).

like image 68
Frederic Maria Avatar answered Sep 19 '22 09:09

Frederic Maria