Git: 如何找到指向特定修订版的标签?

Git: how do I find tags pointing to specific revision?

鉴于一些修改,比如 HEAD^^^,我需要找到指向它的标签。

我可以用 git show-ref --tags | grep $(git rev-parse $REV) | awk '{print }' 来做到这一点。

有专门的命令吗? (这也适用于 Windows。)也许 Git 中甚至有反向引用机制...

编辑

要列出指向给定提交的标签,请使用以下命令:

git tag --points-at 提交

git tag --contains 不是此问题的正确答案,因为它还包含可从中访问指定修订版的后续标记。


git tag -l --contains $REV

来自git tag documentation

-l <pattern>, --list <pattern>

List tags with names that match the given pattern (or all if no pattern is given).

--contains [<commit>]

Only list tags which contain the specified commit (HEAD if not specified).