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.
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.
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...
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.
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.
git tag --points-at HEAD
Shows all tags at HEAD, you can also substitute HEAD with any sha1 id.
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.
git show-ref --tags -d | grep ^48eb354 | sed -e 's,.* refs/tags/,,' -e 's/\^{}//'
should work for both lightweight and annotated tags.
(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.
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