【发布时间】:2011-04-18 09:55:30
【问题描述】:
除了为日期字符串解析 git log 之外,还有 Git 原生的方式来报告某个提交的日期吗?
【问题讨论】:
标签: git
除了为日期字符串解析 git log 之外,还有 Git 原生的方式来报告某个提交的日期吗?
【问题讨论】:
标签: git
【讨论】:
log -1 而不是show。
git show -s --format="%ci" <commit>
%ai查看作者日期。
git show -s --format=%cd --date=short <commit>(例如2016-11-02)或者git show -s --format=%cd --date=short <commit>或者git show -s --format=%cd --date=format:%Y <commit>(这个例子只打印年份)了解详情见this answer。
如果您想自己格式化日期(或小时):
git show -s --date=format:'%Y%m%d-%H%M' --format=%cd <commit id | default is the last commit>
# example output:
20210712-1948
【讨论】:
您可以使用git show 命令。
从 git 存储库中获取最后一次提交日期(Unix 纪元时间戳):
git show -s --format=%ct
1605103148
注意:您可以访问git-show 文档以获取有关选项的更详细说明。
【讨论】:
如果您在使用 windows cmd 命令和 .bat 时遇到问题 就这样逃避百分比
git show -s --format=%%ct
% 字符对于命令行参数和 FOR 参数有特殊的含义。 要将百分比视为常规字符,请将其加倍:%%
【讨论】:
如果你喜欢没有时区但本地时区的时间戳
git log -1 --format=%cd --date=local
这取决于您的位置
Mon Sep 28 12:07:37 2015
【讨论】:
如果您只想查看标签的日期,您可以这样做:
git show -s --format=%ci <mytagname>^{commit}
给出:2013-11-06 13:22:37 +0100
或者做:
git show -s --format=%ct <mytagname>^{commit}
给出 UNIX 时间戳:1383740557
【讨论】: