List all annotated tags, with annotation, sorted by commit date

Viewed 130

It seems easy to list all tags with annotations, with e.g.:

git tag -n99

or

git for-each-ref --format '%(refname:short) %(contents)' refs/tags

And it's also possible to use git log to list tags by creator date, e.g. (from here):

git log --tags --simplify-by-decoration --pretty="format:%cs %d"

However, neither of these answer the question, because as far as I can tell:

  • it is not possible to sort annotated tags by commit date with git tag, because the tags point to a tag annotation object, and so committerdate is empty. You can confirm this with git tag --format='%(committerdate)'
    • There is a creatordate, which lists the commit date for un-annotated commits, and the tag creation date for annotated commits, which is also useless for this question.
  • it is not possible to show the tag annotations with git log, because there is no tag annotation option in the formatter (and this wouldn't make sense anyway, because a single commit can have multiple tags.

So, is there a way to do this that lists all tags, sorted by commit date, and showing both commit date and annotations? I don't care about unannotated tags for this question.

1 Answers

The answer is in the docs

If fieldname is prefixed with an asterisk (*) and the ref points at a tag object, use the value for the field in the object which the tag object refers to (instead of the field in the tag object).

To show the committerdate, use %(*committerdate). For example,

git for-each-ref refs/tags --format="%(*committerdate:iso) %(contents:subject) %(refname:short)" --sort=*committerdate

To reverse the result, use --sort=-*committerdate instead. It's also easy to use sort or sort -r.

Related