以下命令以 json 格式显示有关最后一次 git 提交的一些元数据:
git show --quiet HEAD --pretty=format:"{\"hash\":\"%h\", \"author\":\"%cn\", \"commit date\":\"%cd\"}"
{
"hash":"0fc0fc0",
"author":"Adam Matan",
"commit date":"Sun Jan 26 12:26:19 2014 +0200"}
}
有没有办法在 UTC/GMT 时区中显示日期,例如“2014 年 1 月 26 日星期日 10:26:19”
?
最佳答案
你可以使用这个:
TZ=UTC0 git show --quiet --date=local --format="%cd"
如果要控制日期格式,可以这样做:
TZ=UTC0 git show --quiet --date='format-local:%Y%m%dT%H%M%SZ' --format="%cd"
2021 年 10 月 16 日更新:将 TZ=UTC
更改为 TZ=UTC0
感谢@alex-shpilkin。
关于Git:以 UTC 显示日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21363187/