Git:以UTC显示日期

时间:2014-01-26 12:13:51

标签: git metadata utc

以下命令以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时区中显示日期,例如"Sun Jan 26 10:26:19 2014"

3 个答案:

答案 0 :(得分:10)

您可以使用:

TZ=UTC git show --quiet --date=local --format="%cd"

如果要控制日期格式,可以执行以下操作:

TZ=UTC git show --quiet --date='format-local:%Y%m%dT%H%M%SZ' --format="%cd"

答案 1 :(得分:2)

我在log data formats(列出的this answer)中没有看到utc格式。

我从您的格式中得到的最接近的是:

git config log.date local

C:\Users\VonC\prog\git\git\>git show --quiet HEAD --pretty=format:"{\"hash\":\"%h\", \"author\":\"%cn\", \"commit date\":\"%cd\"}"
{"hash":"b594c97", "author":"Junio C Hamano", "commit date":"Thu Jan 23 10:00:28 2014 -0800"}

C:\Users\VonC\prog\git\git\>git config log.date local

C:\Users\VonC\prog\git\git\Documentation\technical>git show --quiet HEAD --pretty=format:"{\"hash\":\"%h\", \"author\":\"%cn\", \"commit date\":\"%cd\"}"
{"hash":"b594c97", "author":"Junio C Hamano", "commit date":"Thu Jan 23 19:00:28 2014"}

所以来自iso:

"Thu Jan 23 10:00:28 2014 -0800"

到当地:

"Thu Jan 23 19:00:28 2014"

答案 2 :(得分:0)

从技术上讲,git的Unix时间戳格式(例如,通过--date='unix' / --format='%at')也始终采用UTC。有关详细信息,请参见https://git-scm.com/docs/git-log / https://git-scm.com/docs/pretty-formats