git - 在用户的时区中以 ISO 格式显示 git 日志时间戳?

标签 git datetime

使用 --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 log 以更简洁的格式?理想情况下,我希望在 '%C%m%dT%H%M%S' 中看到它们,以使用 unix 日期语法。

最佳答案

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 (2015 年 9 月 3 日)作者 John Keeping (johnkeeping) .
参见 commit add00ba , commit 547ed71 (2015 年 9 月 3 日)作者 Jeff King (peff) .
(由 Junio C Hamano -- gitster -- merge 于 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.

关于git - 在用户的时区中以 ISO 格式显示 git 日志时间戳?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27928167/

相关文章:

c# - SQL 查询的日期时间参数

git - 如何反转 git log --author=me? (不使用 Perl)

git 索引损坏

datetime - 仅 ISO 8601 日期部分

python - Pandas 数据帧 : resample with linear interpolation

java - 如何在UTC区域中获取当前日期作为java 8中的long值

asp.net-mvc - 如何使用ajax将DatePicker创建的日期值传递给mvc 5 Controller

git - 为什么 .gitignore 不起作用?

git - 一个接一个地单独推送一个分支的所有提交

git - 如何让操作系统认为一个目录是另一个目录?