List git tag names, dates and messages
Asked Answered
M

8

39

How do I list the tag name, tag date and tag message for all tags?

It seems that git's separation of display logic for commits through git log and tags through git tag makes it difficult to list the tag name, the tag's date and the tag message.

I can show the tag date, name and commit message using git log --tags --show-notes --simplify-by-decoration --pretty="format:%ai %d %s"

I inspected http://opensource.apple.com/source/Git/Git-26/src/git-htmldocs/pretty-formats.txt but didn't see any option to show tag message.

I can show the tag name and 5 lines of tag message using git tag -n5.

But to get all three pieces of info would appear to require gnarly scripting beyond my ability.

Moncada answered 31/8, 2012 at 16:57 Comment(0)
H
30

You want to use the for-each-ref command. Unfortunately, it's only slightly less user friendly than filter-branch

Note that information like tag date and the tagger is only available for annotated tags.

Below is a basic prototype. Note that the format= can be an entire shell script of its own, and probably should be depending on how complicated you want the output. They have a couple of examples specifically for tags in the for-each-ref documentation

git for-each-ref --format="%(refname:short) %(taggerdate) %(subject) %(body)" refs/tags
Hymenium answered 25/10, 2014 at 14:21 Comment(3)
With a tag created through Github Releases with the autogenerated tag name, this shows the commit message from the related commit, not the message from the tag that was typed into the GUI. That indicates to me that Github isn't using git tag -a but rather some other method?Snarl
It sounds like a non-annotated tag. Those just store a pointer to the SHA.Hymenium
doesn't seem to support git-log format options, like %<(N) for tabular outputMinacious
S
9

git show --tags will at least output all the relevant information about your tags. You might be able to find an appropriate --pretty=format: sequence from there.

Sudatory answered 1/9, 2012 at 1:15 Comment(2)
This looks like a very complicated way to say git show --tags, which by the way does not seem to have a format for what the question author needs.Ailurophobe
@MichałPolitowski Ah yep. git show --tags will do the same thing. Editing the answer accordingly.Sudatory
B
5

git tag --format="%(refname:short) %(authordate) %(authorname) %(subject)"

Example output

0.4.0 Wed Nov 2 11:17:50 2016 -0400 Captain Obvious Release: 0.4.0

Format fields the same as for git-for-each-ref.

Baklava answered 7/8, 2020 at 10:55 Comment(0)
S
4

Use the this terminal command in your repository

git show --tags --no-patch

You can control the format with the same --format= name options (oneline, short, medium, full, custom) used with git log.

git show --tags --no-patch --format=short
Sudatory answered 20/7, 2020 at 2:20 Comment(0)
H
3

How about a bit nicer colorful format?

# ~/.gitconfig
[alias]
tags="for-each-ref --sort=taggerdate --format='%(color:green)%(subject)%(color:reset), tagged: %(refname:short)\n%(taggerdate)\n%(taggername) %(taggeremail)\n\n%(contents:body)\n' refs/tags"

$ git tags 

Release 1.0.1, tagged: 1.0.1
Wed Jul 4 20:16:05 2018 +0430
Sepehr Lajevardi <sepehr.lajevardi@...>

Changelog
- Implement Contentful webhooks to purge internal and CF caches.
- Implement CloudFlareService.
- Fix Contentful's mapping concern usage/namespace. #73
- Temporarily enforce https in og:url property. #103
- Fix entry callback issue with Contentful client. #99
- Fix issue with PPM docker build. #96

Release 1.1.2, tagged: 1.1.2
Thu Jul 12 21:26:29 2018 +0430
Sepehr Lajevardi <sepehr.lajevardi@...>

Changelog
- Fix GA share event issue with AddThis. #132
- Optimize OpenGraph protocol tags for articles. #130
- Optimize Twitter card tags. #131
- Fix HTML validation errors as much as possible. #127


Release 1.1.3, tagged: 1.1.3
Mon Jul 16 22:49:05 2018 +0430
Sepehr Lajevardi <sepehr.lajevardi@...>

Changelog
- Implement cross-device/browser fav/home icons. #137, #138
- Minify HTML output of all pages. #139
- Check for lighthouse score in build pipeline. #30
- Drop AddThis in favor of in-house ShareBar. #116
- Minor article OG tag adjustments.
Hagiography answered 17/7, 2018 at 5:48 Comment(1)
You're missing the opening ' in your alias.Votive
T
1

I don't know if there's a way to

list only the tag name, tag date and tag message for all tags using only the git syntax.

But a simple grep will do the job:

git show --tags |grep "^tag " -A4

Notice I specify 4 lines of trailing context after matching, because the standard output shows tag name, tag date and tag message each on a separate line.

If you need to deal with multiline tag messages I would prefer using piping to awk which is slightly more cumbersome:

git show --tags |awk "/^tag /,/-----BEGIN PGP SIGNATURE-----|commit /" |egrep -v "^$" |sed -E "s/^-----BEGIN PGP SIGNATURE-----.*|^commit.*/-/"

This will work as long as the tag message is followed by either the PGP SIGNATURE or the commit message, which afaik are all the possibile situations. However, you can easily adapt the last grep to cover other situations (if there were to be).

Therein answered 25/10, 2014 at 13:45 Comment(1)
I created my tag with the Github Releases feature using its automatically created tagname (the commit sha). On that repo, the above command does not work, I get no output from the grep and tons of unhelpful output from the git show --tags. Thank you for the idea though!Snarl
H
0

If you want to fetch the latest tag details, use --sort flag, remember that if you are sorting on dates, use '-' before the date to list the newest first.

For example, I wanted the latest tag description (as it happens to be the latest release name), I used --format to just pull the subject of the tag and sort it taggerdate wise (newest first). Here's the command for that.

git for-each-ref --sort=-taggerdate --format '%(subject)' refs/tags --count=1

Hydrocarbon answered 10/3, 2020 at 13:19 Comment(0)
O
-2

This is rather a follow up question to Andrew's response, slightly different but related topic.

git for-each-ref --format="%(refname:short) %(taggerdate) %(subject) %(body)" refs/tags

This works great on direct command line. When I set a git alias in ~/.gitconfig, it does not seem to spew the same output.

When invoked on command line directly, I get.

package-release-14.7.2 Wed Dec 3 14:24:38 2014 -0800 14.7.2: copy for tag package-release-14.7.2
package-release-14.7.3 Thu Dec 4 14:14:55 2014 -0800 14.7.3: copy for tag package-release-14.7.3
package-release-14.7.4 Fri Dec 5 16:16:40 2014 -0800 14.7.4: copy for tag package-release-14.7.4

And when I invoke a git alias(taghist = for-each-ref --format="%(refname:short) %(taggerdate) %(subject) %(body)" refs/tags), I get

package-release-14.7.2
package-release-14.7.3
package-release-14.7.4

-San

Ordination answered 10/12, 2014 at 7:11 Comment(2)
Use \" instead of ", then edit this to provide an answer for how to do it in an alias since otherwise it isn't an answerHymenium
taghist = for-each-ref --format=\"%(refname:short) %(taggerdate) %(subject) %(body)\" refs/tagsOrdination

© 2022 - 2024 — McMap. All rights reserved.