git 日志的格式化输出与非格式化输出不一致

Formatted output for git log inconsistent with non formatted output

我刚刚克隆了 Keras 存储库,并且有兴趣查看 git 日志。我最初尝试使用一种漂亮的格式,并在最后 4 次提交中得到了这个:

me@ARL--M6800:~/Downloads/keras$ git log --pretty=format:"%cn %cd %h"

François Chollet Tue Jan 17 13:29:21 2017 -0800 55487f3
François Chollet Mon Jan 16 17:14:16 2017 -0800 1c6db08
François Chollet Mon Jan 16 10:05:35 2017 -0800 e54d795
François Chollet Sat Jan 14 21:33:04 2017 -0800 82ca6d4

然而,当我没有格式化输出时,我得到了最后 4 次提交的这些结果:

commit 55487f33b135849cdda49bcc75778976d94a2575
Author: Javier Dehesa <javidcf@gmail.com>
Date:   Tue Jan 17 21:29:21 2017 +0000
 ...
commit 1c6db0815853f7c5421b8057e9167f19b5b94812
Author: Petr Baudis <pasky@ucw.cz>
Date:   Tue Jan 17 02:14:16 2017 +0100
...
commit e54d7951f2a82629c71c77ca842ba032b523fe84
Author: Pat York <pat.york@nevada.unr.edu>
Date:   Mon Jan 16 10:05:35 2017 -0800
  ...
commit 82ca6d418588ccd61d663ec8029937290b62d583
Author: Mohanson <mohanson@outlook.com>
Date:   Sun Jan 15 13:33:04 2017 +0800

尽管哈希匹配,但作者和提交日期不匹配。有谁知道这是为什么以及这意味着什么?

似乎 %cd 在一个时区 (-0800) 中显示提交者日期,而默认格式在本地时区中打印日期。这至少有一定的道理,而且时区差异匹配。

关于作者我一无所知...

你应该使用

git log --pretty=format:"%an %ad %h"

as %cn 为您提供提交者姓名和 %an 作者姓名(显示在 "normal" 日志中)

来自手册页:

       ·   %an: author name

       ·   %aN: author name (respecting .mailmap, see git-shortlog(1) or git-blame(1))

       ·   %ae: author email

       ·   %aE: author email (respecting .mailmap, see git-shortlog(1) or git-blame(1))

       ·   %ad: author date (format respects --date= option)

对比

       ·   %cn: committer name

       ·   %cN: committer name (respecting .mailmap, see git-shortlog(1) or git-blame(1))

       ·   %ce: committer email

       ·   %cE: committer email (respecting .mailmap, see git-shortlog(1) or git-blame(1))

       ·   %cd: committer date (format respects --date= option)

       ·   %cD: committer date, RFC2822 style