The --format
option can be used to show both tag hash and the commit hash, and to distinguish between lightweight and annotated tags.
git tag --format="%(color:bold cyan)== %(refname:short) ==%(if)%(object)%(then)%0aTag Hash: %(objectname)%0aTag Date: %(taggerdate:iso-local)%0a Commit: %(object) %0a%0a%(contents)%(else)%0a(lightweight tag)%0a Commit: %(objectname)%(end)%0a"
Gives output similar to:
== b2lightweight ==
(lightweight tag)
Commit: 0450fae4352dbbbf088419757eda32711316a02e
== c3_annotated ==
Tag Hash: 19961d8678a09a319a9d6c398c79f27cc23d610c
Tag Date: 2021-08-06 15:18:48 -0600
Commit: 85be6e80c109ce44d78f0ca0da8e1ec53817b24c
This is my tag message.
It has multiple lines.
Another line.
To define as a git alias, you can edit the global git config with git config --global -e
and add the following:
[alias]
tag-verbose = tag --format='%(color:bold cyan)== %(refname:short) ==%(if)%(object)%(then)%0aTag Hash: %(objectname)%0aTag Date: %(taggerdate:iso-local)%0a Commit: %(object) %0a%0a%(contents)%(else)%0a(lightweight tag)%0a Commit: %(objectname)%(end)%0a'
The alias still allows filtering, e.g.
C:\playground>git tag-verbose -l *b2*
== b2lightweight ==
(lightweight tag)
Commit: 0450fae4352dbbbf088419757eda32711316a02e
For additional information on the --format
options see the "Field Names" section under git help for-each-ref
. (git help tag
states "The format is the same as that of git-for-each-ref")