如何查看日志中每次提交的更改文件?

How can I view changed files for each commit in the log?

我想查看在 git log 的每次提交中更改的文件列表。 Another question asked about how to view the changed files for a single commit, and got the following response:

$ git diff-tree --no-commit-id --name-only -r bd61ad98
index.html
javascript/application.js
javascript/ie6.js

我想知道的是如何将其应用到 git log。也就是说,我应该使用什么命令 运行 得到类似下面的输出?

commit 78b3ba12002f9cab5cbb57fac87d8c703702a196
Author: WD40 <example@example.com>
Date:   Fri Apr 14 09:59:57 2017 -0500

    Change more things

    about.html
    javascript/application.js
    javascript/ie6.js

commit 0f98b1f7eda33a4e9cfaab09506aa8094044085f
Author: WD40 <example@example.com>
Date:   Fri Apr 14 09:49:03 2017 -0500

    Change some things

    index.html
    javascript/application.js
    javascript/ie6.js

此外,如果可能的话,我想知道如何做同样的事情,同时显示添加和删除的文件。

我查看了 git log --format 选项,但找不到与我想要的类似的内容。我有一种感觉,使用 git 日志是不可能的,并且可能需要将多个 git diff-tree 的输出串在一起,但我不确定如果没有脚本(这可能是完成我想要的唯一方法,但我想我会继续问,因为那将是我最后的选择)。

git-log 有很多很多用于显示更改的选项。 They're found in the docs as Common Diff Options,很常见,因为它们被许多可以显示提交的命令共享,例如 git-diff-tree.

--name-only就是你想要的。还有...

  • -p 显示完整补丁
  • --stat显示文件的变化,以及变化的数量
  • --name-status 显示名称及其更改方式(修改、删除...)

还有很多很多!

因此,例如,git log --name-status 可能显示如下内容:

commit 78b3ba12002f9cab5cbb57fac87d8c703702a196
Author: WD40 <example@example.com>
Date:   Fri Apr 14 09:59:57 2017 -0500

    Change more things

A      about.html
M      javascript/application.js
D      javascript/ie6.js

commit 0f98b1f7eda33a4e9cfaab09506aa8094044085f
Author: WD40 <example@example.com>
Date:   Fri Apr 14 09:49:03 2017 -0500

    Change some things

A      index.html
A      javascript/application.js
A      javascript/ie6.js

其中增加了A,修改了M,删除了D