我已经看到了命令 git describe和 git-name-rev,但我还没有设法让他们列出一个以上的标记。
git describe
git-name-rev
示例: 我有 sha148eb354,我知道标记 A 和 B 指向它。因此,我希望 git 命令 git {something} 48eb354能够产生类似于“ A,B”的输出。我对知道相对于其他标记或分支的引用只是标记的精确匹配不感兴趣。
git {something} 48eb354
(Edit: This answer was written long before git tag had the --points-at switch – which is what you would use nowadays.)
git tag
--points-at
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.
git for-each-ref
The following command does the job, but directly parse the content of the .git directory and thus may break if the git repository format change.
grep -l -r -e '^48eb354' .git/refs/tags|sed -e 's,.*/,,'
git show-ref --tags -d | grep ^48eb354 | sed -e 's,.* refs/tags/,,' -e 's/\^{}//'
should work for both lightweight and annotated tags.
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:
that is available only from 1.7.10.
For current commit you can use
git tag --points-at $(git log -n1 --pretty='%H')