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?
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.
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.
You can list all existing tags git tag or you could filter the list with git tag -l 'v1.
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
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With