Get time and date of git tags

I have a project that uses git and tags all 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 release and release dates in the web interface (tag / commit date = release date). We are currently listing all issues using the git tag .

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

+48
git date time git-tag
Nov 03 '12 at 11:30
source share
6 answers

Use the --format argument for git log :

 git log -1 --format=%ai MY_TAG_NAME 
+33
Nov 03 '12 at 11:43
source share

This always worked for me:

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

Refer to the "PRETTY FORMATS" section of the git -log man page for more information on the format string if you want other date formatting.

+56
Nov 03.
source share

Please note that both of the above solutions give you a fix date, which may differ from when this latch was marked for release. To get the date of the tag itself, you need to find the rev-parse tag itself, read it with cat-file , and then rev-parse it. Small pipeline:

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

+19
Dec 12 '14 at 2:43 on
source share

Another 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) indicates the commit date to see the date the tag was created when using %(taggerdate)

You can directly enable the shell:

 $> 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' 
+6
Feb 12 '17 at 18:39
source share

you can use gawk (not awk ) to convert the date in the string "tagger" to something human readable:

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

if you don't 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 
+1
Dec 03 '15 at 12:56
source share

The git tag command has no easy option for this. I found the most convenient to run

 git log --decorate=full 

to list all commits, including tags, if any. For enumeration only commits marked using tags

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

See details

 git help log 
+1
May 09 '16 at 9:36 a.m.
source share



All Articles