Seeing what revision goes with a tag in Git

孤者浪人 提交于 2019-12-10 12:31:37

问题


Beginner Git question:

In the Mercurial world, hg tags gives me a list of tags and the corresponding revisions, whereas git tag only lists the tag names. How do I see what the matching rev number/hash is?


回答1:


For full information associated with that tag, use command

git show v1.5

Or you can see the lightweight information, skipping details, by command

git show v1.5 -lw



回答2:


If tag in question is so called 'heavyweight tag', or annotated tag, utilizing tag object, e.g. PGP signed version (as far as I know Mercurial doesn't have equivalent) then

$ git show v1.5.0

would show both tag info (tagger, tagging date, tag message - usually containing PGP signature block), and information about tagged commit. If you prefer, you can use low-level equivalent:

$ git cat-file tag v1.5.0

(this would fail if v1.5.0 is not a tag object).

If tag in question is so called 'lightweight tag', it is simply a reference in refs/tags/* namespace. You can use "git show lightweight-tag" to show a commit pointed by a given tag.

You can use tag name in every place that expect commit-ish, or tree-ish.


If you want more than what "git tag" / "git tag -l" offers, you can use one of the following plumbing (low-level) commands git show-refs:

$ git show-ref --tags
$ git show-ref --dereference --tags

or git for-each-ref, which offer extracting more information with --format=<format> option, and sorting with --sort=<key> option:

$ git for-each-ref refs/tags/

You can also (ab)use git ls-remote for this, resulting in output similar to "git show-ref --dereference --tags":

$ git ls-remote --tags .


来源:https://stackoverflow.com/questions/1194385/seeing-what-revision-goes-with-a-tag-in-git

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!