168

I have a project that is using git and have tagged all the releases with a tag.

$ git tag
v1.0.0
v1.0.1
v1.0.2
v1.0.3
v1.1.0

My goal is to list the releases and release dates in a web interface (tag/commit date = release date). Currently we list all the releases by using git tag.

How can I get the time and date for when the tag was made (or the commit it points to)?

6
  • 3
    It's good to precise here that it's the commit date of the tag that you're after. As a tag has no date. Commented Jun 1, 2017 at 5:51
  • Possible duplicate of How can I list all tags in my Git repository by the date they were created? Commented Feb 21, 2018 at 13:12
  • 4
    @jobwat Annotated tags do have a date. Commented Aug 24, 2018 at 7:50
  • 3
    TL;DR if you want a tag date, and not underlying commit date, you can't use git log, but must use git-for-each-ref. In my case I wanted relative time (%ar from git log); I managed to have it with: git for-each-ref --format="%(creatordate:relative)" refs/tags/MYTAG Commented Jun 3, 2022 at 14:57
  • Just adding, if you want an actual date for the tag date, as mentioned in @jakub.g 's comment, you can do the following: git for-each-ref --format="%(creatordate)" refs/tags/MYTAG, removing the :relative. Commented Jun 21, 2023 at 3:29

9 Answers 9

156

This always worked for me:

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

Consult the "PRETTY FORMATS" section of the git-log manpage for details of the format string if you want a different date formatting.

Sign up to request clarification or add additional context in comments.

2 Comments

To be warned though, this will list the date/time for commit, but not the date/time for the annotated tag.
Just put taglog = log --tags --simplify-by-decoration --pretty='format:%ci %d' (note the single-, NOT double-quotes) in the [alias] section of your .gitconfig file, and now you've got a git taglog command :)
104

Use the --format argument to git log:

git log -1 --format=%ai MY_TAG_NAME

7 Comments

TIP - Replace "TAG" with the tag name. For example, git log -1 --format=%ai v0.2.3.
If you want ISO8601, do --format=%aI (capital "I")
What's "-1" doing?
This answer prints the author date of the tagged commit, not the date the tag was created.
The tag date can be gotten with git for-each-ref --format="%(creatordate)" refs/tags/MYTAG (replace MYTAG with your own tag).
|
99

One more option:

git for-each-ref --format="%(refname:short) | %(creatordate)" "refs/tags/*"

See https://git-scm.com/docs/git-for-each-ref#_field_names for format options

%(creatordate) gives the date of the commit pointed to, to see the date the tag was created on use %(taggerdate)

You can incorporate the shell directly:

$> git for-each-ref --shell --format="ref=%(refname:short) dt=%(taggerdate:format:%s)" "refs/tags/*"

ref='v1.10' dt='1483807817'
ref='v1.11' dt='1483905854'
ref='v1.12.0' dt='1483974797'
ref='v1.12.1' dt='1484015966'
ref='v1.13' dt='1484766542'
ref='v1.2' dt='1483414377'
ref='v1.3' dt='1483415058'
ref='v1.3-release' dt='' <-- not an annotated tag, just a pointer to a commit so no 'taggerdate', it would have a 'creator date'.
ref='v1.3.1' dt='1483487085'
ref='v1.4' dt='1483730146'
ref='v1.9' dt='1483802985'

11 Comments

This is the best answer for getting the tag date.
Alternatively, you can get the unix timestamp with git for-each-ref --format="%(taggerdate:unix)" refs/tags or as substring in git for-each-ref --format="%(taggerdate:raw)" refs/tags
Thank you! All of the other answers just give the commit date and not the tag date.
Yes defo best answer as it only shows the actual tags, not all commits, shame crappy SO has other answers rated higher.
same result with less typing: git tag --format "%(refname:short) %(creatordate:short)"
|
30

Note that both of the above solutions get you the commit date, which can be wildly different than when that commit was tagged for release. To get the date of the tag itself, you've got to find the tag itself with rev-parse, read it with cat-file, and then parse it. A little pipeline:

git rev-parse v1.0.0 | xargs git cat-file -p | egrep '^tagger' | cut -f2 -d '>'

3 Comments

Good, only problem is the result is not formatted (1419372909 -0300)
Once you have the commit id from rev-parse, I believe you can do: git rev-parse v1.0.0 | xargs git show -s --pretty=%aI
@Keith Now you're back to showing the author date of the commit instead of the tagged date, at least for annotated tags
3

There is no simple option in git tag command to do this. I found most convenient to run

git log --decorate=full

to list all commits including tags if there are some. For listing only commits that are tagged use

git log --decorate=full --simplify-by-decoration

For details use

git help log

Comments

2

one can use gawk (not awk) to convert date in the "tagger" line to something human-readable:

git rev-parse v4.4-rc1 | xargs git cat-file -p | gawk '/^tagger/ { print strftime(PROCINFO["strftime"], $(NF-1)) }'

if one does not like gawk then date can be used to convert unix time:

git rev-parse v2.76 | xargs git cat-file -p | awk '/^tagger/ { print "@" $(NF-1) }' | xargs date -d

and example (dnsmasq git repo):

$ git rev-parse v2.76 | xargs git cat-file -p | awk '/^tagger/ { print "@" $(NF-1) }' | xargs date -d
Wed May 18 16:52:12 CEST 2016

2 Comments

do you try this from yourside??
surely. it works, dnsmasq git repo, for example: $ git rev-parse v2.76 | xargs git cat-file -p | awk '/^tagger/ { print strftime(PROCINFO["strftime"], $(NF-1)) }' Wed May 18 16:52:12 CEST 2016
2

All of the answers here are great and in the proper git style. But I needed a tag, its date and its message and only the last 10 tags. So I just did it in a very pedestrian way. But save it as a shell function or script and it becomes a one-liner.

for ver in `git tag | tail -10`; do
    DATE=`git log -1 --format=%ai $ver | awk '{print $1}'`
    MESSAGE=`git tag -n $ver | cat | awk '{a=match($0, $2); print substr($0,a)}'`
    echo "$ver \t| $DATE | $MESSAGE"
done

Comments

2

Answers above gave me wrong dates for my tag date, I don't know why, so here is what finally worked for me:

git tag --list "$MY_TAG_NAME" --format="%(taggerdate)"
Tue Oct 29 14:47:46 2024 +0100

You can also have the timestamp by doing this instead:

git tag --list "$MY_TAG_NAME" --format="%(taggerdate:unix)"
1730209666

1 Comment

this answer should work once you add creatordate instead: git for-each-ref --format="%(refname:short) | %(taggerdate)" "refs/tags/*"
0

I use this script which deletes tags with last commit over a year ago. Also, it assumes the "origin" name for the remote repository.

#!/bin/bash
# Timestamp one year ago - use whatever time stamp you you like
some_time_in_the_past=$(date --date="1 year ago" +%s)

# Gå through all tags
for tag in $(git tag); do
    # Get date for last commit in the annotated tag
    tag_date=$(git log -1 --format=%ct "$tag")
    if [ "$tag_date" -lt "$some_time_in_the_past" ]; then
        echo "Removing tag: $tag"
        # Remove tag locally
        git tag -d "$tag"
        # Remove tag from origin (classic method)
        # git push origin :refs/tags/"$tag"
        # Alternative method (newer Git-versions):
        git push --delete origin "$tag"
    fi
done

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.