Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I list all tags in my Git repository by the date they were created?

Tags:

git

People also ask

How will you list your tags in git?

List Local Git Tags. In order to list Git tags, you have to use the “git tag” command with no arguments. You can also execute “git tag” with the “-n” option in order to have an extensive description of your tag list. Optionally, you can choose to specify a tag pattern with the “-l” option followed by the tag pattern.

How can I see my repository tags?

View tags for a repository (console)In Repositories, choose the name of the repository where you want to view tags. In the navigation pane, choose Settings. Choose Repository tags.

How do I fetch all tags?

To fetch tags from your remote repository, use “git fetch” with the “–all” and the “–tags” options. Let's say for example that you have a tag named “v1. 0” that you want to check out in a branch named “release”. Using this command, you have successfully checked out the “v1.


Sorting by tag creation date works with annotated and lightweight tags:

git for-each-ref --sort=creatordate --format '%(refname) %(creatordate)' refs/tags

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 and creator fields will correspond to the appropriate date or name-email-date tuple from the committer or tagger 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

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

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.


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.


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.