views:

448

answers:

2

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?

+3  A: 

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
simplyharsh
That's actually more detail than I need, but it'll do - thanks. Turns out git log <rev_name> works too. D'oh.
fakeleft
git log gives you list of revisions. And when you ask revision corresponding to a tag, this is the answer.
simplyharsh
+3  A: 

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 .
Jakub Narębski
...and if you don't know/care whether the tag is a tag object or a lightweight label but want to see just the commit you can use `git show v1.5.0^{commit}`, or `git rev-parse v1.5.0^{commit}` for a scriptable way to retrieve the commit id.
Charles Bailey
Or just `v1.5.0^{}` (assuming that tag points to a commit)
Jakub Narębski