Reputation: 3192
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?
Upvotes: 231
Views: 109256
Reputation: 52499
Note: my git --version
is git version 2.25.1
.
Note that for all commands below, if your tags are annotated tags, meaning you gave them a message, then use --sort=taggerdate
. If your tags are not annotated with an attached messsage, however, then they are considered "lightweight tags", so use --sort=creatordate
instead. See here: why sort by taggerdate does not really work?:
Only annotated tags have their own separate tagger date. As long as the tag is for a commit, both annotated tags and lightweight tags will have a "creator date", but only the annotated tags will have a separate "tagger date" here. Displaying both values helps sort this out
Read more about "Annotated Tags" and "Lightweight Tags" here: https://git-scm.com/book/en/v2/Git-Basics-Tagging.
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 # for annotated tags
git tag -l -n99 --sort=creatordate # for lightweight tags
(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 # for annotated tags
git tag -l -n99 --sort=-creatordate # for lightweight tags
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*' # for annotated tags
git tag -l -n99 --sort=-creatordate '*my string*' # for lightweight tags
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*' # for annotated tags
git tag -l --sort=-creatordate '*my string*' # for lightweight tags
Upvotes: 8
Reputation: 1323793
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
With Git 2.44 (Q1 2024), rc1, "git branch
"(man) and friends learned to use the formatted text as sorting key, not the underlying timestamp value, when the --sort
option is used with author or committer timestamp with a format specifier (e.g., "--sort=creatordate:format:%H:%M:%S
").
See commit 46176d7 (08 Feb 2024) by Victoria Dye (vdye
).
(Merged by Junio C Hamano -- gitster
-- in commit d4833b2, 12 Feb 2024)
ref-filter.c
: sort formatted dates by byte valueSigned-off-by: Victoria Dye
Update the ref sorting functions of '
ref-filter.c
' so that when date fields are specified with a format string (such as in 'git for-each-ref --sort=creatordate:<something>
'(man) ), they are sorted by their formatted string value rather than by the underlying numeric timestamp.Currently, date fields are always sorted by timestamp, regardless of whether formatting information is included in the '
--sort
' key.Leaving the default (unformatted) date sorting unchanged, sorting by the formatted date string adds some flexibility to '
for-each-ref
' by allowing for behavior like "sort by year, then by refname within each year" or "sort by time of day".Because the inclusion of a format string previously had no effect on sort behavior, this change likely will not affect existing usage of '
for-each-ref
' or other ref listing commands.
git for-each-ref
now includes in its man page:
As a special case for the date-type fields, you may specify a format for the date by adding
:
followed by date format name (see the values the--date
option togit rev-list
takes).If this formatting is provided in a
--sort
key, references will be sorted according to the byte-value of the formatted string rather than the numeric value of the underlying timestamp.
Upvotes: 105
Reputation: 872
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.
Upvotes: 37
Reputation: 177550
Sorting by tag creation date works with annotated and lightweight tags:
git for-each-ref --sort=creatordate --format '%(refname) %(creatordate)' refs/tags
Upvotes: 295
Reputation: 77
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.
Upvotes: 7
Reputation: 4346
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 }'
Upvotes: 3
Reputation: 5024
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.
Upvotes: 22
Reputation: 48753
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
Upvotes: 40
Reputation: 5463
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.
Upvotes: 12