以用户时区的 ISO 格式显示 git 日志时间戳?
show git log timestamps in ISO format in user's timezone?
使用 --date=local
git log
显示我(用户)时区的日期:
$ git log --date=local -3 --pretty=tformat:'%cd %h' --abbrev-commit
Thu Dec 18 15:22:11 2014 dc20f74
Thu Dec 18 14:01:26 2014 06c214f
Tue Nov 4 03:48:44 2014 ac33158
man-page 表示
-- date [...] Only takes effect for dates shown in human-readable format, such as when using --pretty.
但是对于 ISO 格式 %ci
它不会生效,事实上 --date=local
和 --date=default
产生完全相同的输出:
$ git log --date=local -3 --pretty=tformat:'%ci %h' --abbrev-commit
2014-12-18 23:22:11 +0000 dc20f74
2014-12-18 22:01:26 +0000 06c214f
2014-11-04 17:18:44 +0530 ac33158
$ git log --date=default -3 --pretty=tformat:'%ci %h' --abbrev-commit
2014-12-18 23:22:11 +0000 dc20f74
2014-12-18 22:01:26 +0000 06c214f
2014-11-04 17:18:44 +0530 ac33158
我如何才能看到 git 以本地时区的较简洁格式登录?理想情况下,我希望在 '%C%m%dT%H%M%S'
中看到它们,以使用 unix 日期语法。
似乎无法显示转换为本地用户时区的%ci
(ISO时间格式);它总是显示在提交者的时区。您可以使用 %ct
并解析输出并使用 date
或其他脚本之类的实用程序重新格式化它,或者使用 %cd
.
git 2.7(2015 年第 4 季度)将成为可能,它引入了 -local
作为指令。
意思是,除了:
--date=(relative|local|default|iso|iso-strict|rfc|short|raw)
您还将拥有:
--date=(relative-local|default-local|iso-local|iso-strict-local|rfc-local|short-local|raw-local)
您现在可以使用当地时区请求任何日期格式。
你的情况:
git log --date=iso-local -3 --pretty=tformat:'%cd %h' --abbrev-commit
^^^^^^^^^
|____| that part is new!
参见 commit 99264e9, commit db7bae2, commit dc6d782, commit f3c1ba5, commit f95cecf, commit 4b1c5e1, commit 8f50d26, commit 78a8441, commit 2df4e29 (03 Sep 2015) by John Keeping (johnkeeping
)。
参见 commit add00ba, commit 547ed71 (03 Sep 2015) by Jeff King (peff
)。
(由 Junio C Hamano -- gitster
-- in commit 7b09c45 合并,2015 年 10 月 5 日)
特别是,commit add00ba 提到:
date
: make "local
" orthogonal to date format:
Most of our "--date
" modes are about the format of the date: which items we show and in what order.
But "--date=local
" is a bit of an oddball. It means "show the date in the normal format, but using the local timezone".
The timezone we use is orthogonal to the actual format, and there is no reason we could not have "localized iso8601", etc.
This patch adds a "local
" boolean field to "struct date_mode
", and drops the DATE_LOCAL
element from the date_mode_type
enum (it's now just DATE_NORMAL
plus local=1
).
The new feature is accessible to users by adding "-local
" to any date mode (e.g., "iso-local
"), and we retain "local
" as an alias for "default-local
" for backwards compatibility.
使用 --date=local
git log
显示我(用户)时区的日期:
$ git log --date=local -3 --pretty=tformat:'%cd %h' --abbrev-commit
Thu Dec 18 15:22:11 2014 dc20f74
Thu Dec 18 14:01:26 2014 06c214f
Tue Nov 4 03:48:44 2014 ac33158
man-page 表示
-- date [...] Only takes effect for dates shown in human-readable format, such as when using --pretty.
但是对于 ISO 格式 %ci
它不会生效,事实上 --date=local
和 --date=default
产生完全相同的输出:
$ git log --date=local -3 --pretty=tformat:'%ci %h' --abbrev-commit
2014-12-18 23:22:11 +0000 dc20f74
2014-12-18 22:01:26 +0000 06c214f
2014-11-04 17:18:44 +0530 ac33158
$ git log --date=default -3 --pretty=tformat:'%ci %h' --abbrev-commit
2014-12-18 23:22:11 +0000 dc20f74
2014-12-18 22:01:26 +0000 06c214f
2014-11-04 17:18:44 +0530 ac33158
我如何才能看到 git 以本地时区的较简洁格式登录?理想情况下,我希望在 '%C%m%dT%H%M%S'
中看到它们,以使用 unix 日期语法。
似乎无法显示转换为本地用户时区的%ci
(ISO时间格式);它总是显示在提交者的时区。您可以使用 %ct
并解析输出并使用 date
或其他脚本之类的实用程序重新格式化它,或者使用 %cd
.
git 2.7(2015 年第 4 季度)将成为可能,它引入了 -local
作为指令。
意思是,除了:
--date=(relative|local|default|iso|iso-strict|rfc|short|raw)
您还将拥有:
--date=(relative-local|default-local|iso-local|iso-strict-local|rfc-local|short-local|raw-local)
您现在可以使用当地时区请求任何日期格式。
你的情况:
git log --date=iso-local -3 --pretty=tformat:'%cd %h' --abbrev-commit
^^^^^^^^^
|____| that part is new!
参见 commit 99264e9, commit db7bae2, commit dc6d782, commit f3c1ba5, commit f95cecf, commit 4b1c5e1, commit 8f50d26, commit 78a8441, commit 2df4e29 (03 Sep 2015) by John Keeping (johnkeeping
)。
参见 commit add00ba, commit 547ed71 (03 Sep 2015) by Jeff King (peff
)。
(由 Junio C Hamano -- gitster
-- in commit 7b09c45 合并,2015 年 10 月 5 日)
特别是,commit add00ba 提到:
date
: make "local
" orthogonal to date format:Most of our "
--date
" modes are about the format of the date: which items we show and in what order.
But "--date=local
" is a bit of an oddball. It means "show the date in the normal format, but using the local timezone".
The timezone we use is orthogonal to the actual format, and there is no reason we could not have "localized iso8601", etc.This patch adds a "
local
" boolean field to "struct date_mode
", and drops theDATE_LOCAL
element from thedate_mode_type
enum (it's now justDATE_NORMAL
pluslocal=1
).
The new feature is accessible to users by adding "-local
" to any date mode (e.g., "iso-local
"), and we retain "local
" as an alias for "default-local
" for backwards compatibility.