I need some way to list all tags in my system by the date they were created but am not sure if I can get that data via git-log. Ideas?
-
2Do you mean that you want to get the list of all tags _in order_ of there creation dates? – lithuak Jun 07 '11 at 18:43
-
5FYI **(1.)** [This question](https://stackoverflow.com/q/6269927/52074) is for listing ANNOTATED tags by date. **(2.)** For listing LIGHTWEIGHT tags by date, [go here](https://stackoverflow.com/q/6900328/52074). **(3.)** For a helpful reminder on what is the difference between Git's lightweight vs annotated tags, [go here](https://stackoverflow.com/q/4971746/52074). – Trevor Boyd Smith Feb 21 '18 at 13:04
-
@TrevorBoydSmith: That's not quite correct. The difference is that (2) lists all tags by _commit date_ of the _tagged commit_, whereas this page gives solutions that sort by _date tagged_ (though only for annotated tags, since git doesn't store date tagged for lightweight tags). – David P Aug 01 '18 at 14:31
10 Answers
Sorting by tag creation date works with annotated and lightweight tags:
git for-each-ref --sort=creatordate --format '%(refname) %(creatordate)' refs/tags

- 3,297
- 5
- 35
- 50

- 171,072
- 38
- 269
- 275
-
13Awesome. `git for-each-ref --format="%(taggerdate): %(refname)" --sort=-taggerdate --count=10 refs/tags` did exactly what I needed. Thanks! – Jon Ursenbach Jun 07 '11 at 18:58
-
23A solution by @DrorCohen which works for lightweight tags: http://stackoverflow.com/questions/6900328/git-command-to-show-all-lightweight-tags-creation-dates. Pasting here for easy reference: git log --tags --simplify-by-decoration --pretty="format:%ai %d" – Gilead Oct 24 '12 at 13:02
-
6Can use `%(contents)` to add in annotation if needed, e.g. `git for-each-ref --sort='*authordate' --format='%(taggerdate:short) | %(tag) | %(contents)' refs/tags ` – Tim Diggins May 14 '13 at 11:34
-
1this doesn't work if your tags are formatted like this: `1.1, 1.2...1.11, 1.12...1.20...etc`. The date itself doesn't come into play when sorting, but the tag name itself. You will get some order looking like this: `1.1, 1.11, 1.12, 1.2, 1.20` – hellatan Oct 28 '13 at 16:11
-
@hellatan Thanks! I hadn’t even noticed that they were sorted by name. – Josh Lee Oct 28 '13 at 16:27
-
np @JoshLee. we were looking for a way to get the latest tag at work and i thought this might work but then ran into that problem. ended up using this instead: `git describe --abbrev=0` – hellatan Oct 31 '13 at 01:22
-
9Or even a bit cleaner: `git for-each-ref --sort=taggerdate --format '%(tag)'` – Baris Wanschers Sep 08 '14 at 15:05
-
1I notice that taggerdate can be empty but creatordate always exists: so I use: git for-each-ref --sort=creatordate --format '%(refname) %(creatordate) %(taggerdate)' refs/tags – teng_wenxuan Apr 14 '17 at 19:57
-
5`--sort=creatordate` works for both annotated and unannotated tags, but `--sort=taggerdate` only seems to work with annotated tags. tested using `git version 2.16.3` – austinheiman Aug 06 '18 at 16:55
-
-
@austinheiman solution works for me. Using taggerdate continued to sort alphabetically but creatordate works perfectly – Arj Jan 07 '20 at 15:54
-
1I ended up setting `tag.sort=creatordate` in my `~/.gitconfig`. Now tags appear as I expect them to when using the git CLI. That is, tag "1.0.2" appears immediately after "1.0.1", not with "1.0.10" between them, because that's not the order they were created. (However, Atlassian's SourceTree still doesn't show them in the correct order. ) – Mr. Lance E Sloan Jan 31 '20 at 17:17
-
-
Found it. To reverse the order and display with newest date on top, you can pipe to `tac` (`cat` backwards), like this: `git for-each-ref --sort=creatordate --format '%(refname) %(creatordate)' refs/tags | tac`. Source: [How can I reverse the order of lines in a file?](https://stackoverflow.com/questions/742466/how-can-i-reverse-the-order-of-lines-in-a-file/742485#742485) – Gabriel Staples Sep 19 '21 at 08:04
-
And [here is my own answer with an alternative form](https://stackoverflow.com/a/69241512/4561887), including reversing the chronological list order of the tags. – Gabriel Staples Sep 19 '21 at 08:17
Git 2.8 (March 2016) documents another option dating back to git 1.4.4 (Oct2006).
See commit e914ef0 (05 Jan 2016) by Eric Wong (ele828
).
(Merged by Junio C Hamano -- gitster
-- in commit 108cb77, 20 Jan 2016)
See the new Documentation/git-for-each-ref.txt
For commit and tag objects, the special
creatordate
andcreator
fields will correspond to the appropriate date or name-email-date tuple from thecommitter
ortagger
fields depending on the object type.
These are intended for working on a mix of annotated and lightweight tags.
So using creatordate
works with tags:
git for-each-ref --format='%(*creatordate:raw)%(creatordate:raw) %(refname) %(*objectname) %(objectname)' refs/tags | \
sort -n | awk '{ print $4, $3; }'
Or:
git tag --sort=-creatordate
As I detail in "How to sort git tags by version string order of form rc-X.Y.Z.W?", you can add a sort order to git tag
(since Git 2.0 June 2014).
That sort order includes as field name (listed in git for-each-ref
) taggerdate. That allows for git tag --sort=taggerdate
(mentioned by DarVar below)
As an example, in the git/git
repo it will list the v2.10.0
tag last:
v2.9.1
v2.9.2
v2.9.3
v2.10.0-rc0
v2.10.0-rc1
v2.10.0-rc2
v2.10.0
The default order would not (git tag
):
v2.1.2
v2.1.3
v2.1.4
v2.10.0
v2.10.0-rc0
v2.10.0-rc1
v2.10.0-rc2
v2.2.0
-
Thanks a lot. I was wondering why some dates were empty. I was already suspecting lightweight tags. I'm glad I don't need to recreate the tags thanks to `creatordate`! – exhuma Dec 28 '17 at 14:12
git log --tags --simplify-by-decoration --pretty="format:%ci %d"
Also nice output from (without date field):
git log --tags --decorate --simplify-by-decoration --oneline
To see full history with dependencies and striped linear commits (only essential events, like tagging and branching/merging):
git log --graph --decorate --simplify-by-decoration --oneline --all

- 45,285
- 19
- 251
- 303
-
For lazy people: `git log --tags --simplify-by-decoration --pretty="format:%ci %d" | grep "tag:"` and it works best for me. – Mateusz Jun 25 '15 at 08:13
-
4Note that this is ordered by the commit date, not the date the tags were created. The (currently) top rated answer from Josh Lee does order by the date the tag was created. – Nathanial Woolls Sep 14 '16 at 17:26
This one-liner displays dates & tags:
git tag --format='%(creatordate:short)%09%(refname:strip=2)'
Output:
2015-09-27 v0.1.0
2019-10-22 v0.10.0
2020-07-08 v0.12.0
2015-11-18 v0.2.0
2020-12-08 v1.0.0
Tags are sorted in lexicographic order by default. If you prefer to sort by date:
git tag --format='%(creatordate:short)%09%(refname:strip=2)' --sort=creatordate
Output:
2015-09-27 v0.1.0
2015-11-18 v0.2.0
2019-10-22 v0.10.0
2020-07-08 v0.12.0
2020-12-08 v1.0.0
See VonC answer for more details.

- 818
- 9
- 18
-
Is this nice method bound to sort them by date? ascending? descending? – Motti Shneor Oct 31 '19 at 12:59
git tag --sort=-taggerdate
According to the man page, "Prefix - to sort in descending order of the value. "
git tag
uses the same sorting keys as git-for-each-ref
, which is where the keys are documented.

- 4,626
- 1
- 37
- 42
-
1This is probably the most correct based on question. Here is the link to the docs outlining the possible sort fields: https://git-scm.com/docs/git-for-each-ref – prasanthv Apr 30 '18 at 20:19
-
This response doesn't take into account lightweight tags as they have empty "taggerdate". Other responses with "creatordate" are more accurate. – morhook Jun 03 '20 at 15:18
-
1`git --no-pager tag --sort=-creatordate` seems to be more what I needed – Alex Nolasco Apr 26 '23 at 13:11
To have annotated tags and lightweight tags sorted altogether, based on the commit date, I'm using:
git for-each-ref --format='%(*committerdate:raw)%(committerdate:raw) %(refname) %(*objectname) %(objectname)' refs/tags | \
sort -n | awk '{ print $4, $3; }'
This command will list every tag and the associated commit object id, in chronological order.

- 5,277
- 1
- 23
- 39
-
Obfuscated a bit. ... In annotated tags, 'committerdate' is empty whereas in lightweight tags 'taggerdate' is empty. So as a workaround '*committerdate' is telling Git to backreference dates from the original commit object when it's lightweight. ... – ingyhere Nov 15 '17 at 20:52
-
The following relies on the commit, so it doesn't matter if it has date information with the commit:
git log --tags --decorate --simplify-by-decoration|grep ^commit|grep tag|sed -e 's/^.*: //' -e 's/)$//' -e 's/,.*$//'|tac
The answer above by Josh Lee, relies on a tag date to get the order correct.

- 77
- 1
- 2
-
Not sure what the trailing command `tac` is - might change it to `more`. Anyway your command worked great - thanks! – David H May 08 '18 at 19:53
-
https://unix.stackexchange.com/questions/114041/how-can-i-get-the-tac-command-on-os-x – Andrew McGlashan May 11 '18 at 05:03
-
Note: my git --version
is git version 2.25.1
.
For a list -l
of all tags, with up to 99 lines in the message field per tag (-n99
), in chronological order with the newest tag last, do:
git tag -l -n99 --sort=taggerdate
(My preferred form) to reverse the chronological order and put the newest tag first, add a minus sign (-
) in front of taggerdate
, like this:
git tag -l -n99 --sort=-taggerdate
Going further:
To also search within the tags and only show tags which contain string my string
somewhere in their name, add '*my string*'
to the end. Note that the asterisks (*
) are wild-cards in the search pattern:
git tag -l -n99 --sort=-taggerdate '*my string*'
To only show the tag names, and NOT up to 99 lines of their tag messages, simply remove the -n99
part:
git tag -l --sort=-taggerdate '*my string*'
Related
- My answer on how to show all tags in git log

- 36,492
- 15
- 194
- 265
Building on the earlier mentioned methods, I wanted to also see the actual tag date on the list, and so my in-use version is:
git for-each-ref --format='%(*creatordate:raw)%(creatordate:raw) %(creatordate:short) %(refname) %(*objectname) %(objectname)' refs/tags | sort -n | awk '{ print $3, $5, $4 }'

- 4,088
- 2
- 37
- 38