Get the time and date of git tags

后端 未结 7 1295
逝去的感伤
逝去的感伤 2021-01-30 15:37

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

相关标签:
7条回答
  • 2021-01-30 15:59

    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.

    0 讨论(0)
  • 2021-01-30 16:10

    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'
    
    0 讨论(0)
  • 2021-01-30 16:11

    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 '>'

    0 讨论(0)
  • 2021-01-30 16:15

    Use the --format argument to git log:

    git log -1 --format=%ai MY_TAG_NAME
    
    0 讨论(0)
  • 2021-01-30 16:15

    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
    
    0 讨论(0)
  • 2021-01-30 16:23

    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
    
    0 讨论(0)
提交回复
热议问题