List git tag names, dates and messages

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.

Answers


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

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.


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).


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.

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


Need Your Help

How do comment @replies work?

support faq comments notifications comment-replies

How do the comment replies (aka "pinging users") work?

Django Forms and Bootstrap - CSS classes and <divs>

css django twitter-bootstrap

I'm using Twitter Bootstrap with Django to render forms.