git 获取git标签的时间和日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13208734/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get the time and date of git tags
提问by HNygard
I have a project that is using git and have tagged all the releases with a tag.
我有一个使用 git 的项目,并用标签标记了所有版本。
$ 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
.
我的目标是在 Web 界面中列出发布和发布日期(标签/提交日期 = 发布日期)。目前我们使用git tag
.
How can I get the time and date for when the tag was made (or the commit it points to)?
我如何获得标签制作(或它指向的提交)的时间和日期?
采纳答案by user4815162342
Use the --format
argument to git log
:
使用--format
参数git log
:
git log -1 --format=%ai MY_TAG_NAME
回答by Nikos C.
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.
如果您想要不同的日期格式,请查阅 git-log 联机帮助页的“PRETTY FORMATS”部分以了解格式字符串的详细信息。
回答by non sequitor
One more option:
还有一种选择:
git for-each-ref --format="%(refname:short) | %(creatordate)" refs/tags/*
See https://git-scm.com/docs/git-for-each-ref#_field_namesfor format options
有关格式选项,请参阅https://git-scm.com/docs/git-for-each-ref#_field_names
%(creatordate)
gives the date of the commit pointed to, to see the date the tag was created on use %(taggerdate)
%(creatordate)
给出指向的提交日期,以查看标签在使用时创建的日期 %(taggerdate)
You can incorporate the shell directly:
您可以直接合并 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'
回答by Rob Shearer
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:
请注意,上述两种解决方案都会为您提供提交日期,这可能与该提交被标记为发布时有很大不同。要获取标签本身的日期,您必须使用 找到标签本身rev-parse
,使用 读取它cat-file
,然后解析它。一个小管道:
git rev-parse v1.0.0 | xargs git cat-file -p | egrep '^tagger' | cut -f2 -d '>'
git rev-parse v1.0.0 | xargs git cat-file -p | egrep '^tagger' | cut -f2 -d '>'
回答by vladis
one can use gawk
(not awk
) to convert date in the "tagger" line to something human-readable:
可以使用gawk
(not awk
) 将“标记器”行中的日期转换为人类可读的内容:
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:
如果不喜欢gawk
那么date
可以用来转换unix时间:
git rev-parse v2.76 | xargs git cat-file -p | awk '/^tagger/ { print "@" $(NF-1) }' | xargs date -d
and example (dnsmasq
git repo):
和示例(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
回答by VojtaK
There is no simple option in git tag command to do this. I?found most convenient to run
git tag 命令中没有简单的选项来执行此操作。我发现最方便运行
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