当我执行gitdiffCOMMIT时,我看到了提交和HEAD之间的变化(据我所知),但我希望看到单个提交所做的变化。

我还没有在diff/log上找到任何明显的选项来提供输出。


当前回答

我在windows 10上运行的是Git 2.6.1.windows.1版本,所以我需要对Nevik的答案稍作修改(用波浪号代替插入符号):

git diff COMMIT~ COMMIT

另一个选项是引用插入符号:

git diff "COMMIT^" COMMIT

其他回答

gitshow显示了最近一次提交中所做的更改。它相当于git show HEAD。

git show HEAD~1会让您返回一次提交。

以下内容似乎可以完成任务:;我用它来显示合并带来了什么。

git whatchanged -m -n 1 -p <SHA-1 hash of merge commit>

我通常会:

git diff HEAD~1

显示有关上次提交的更改。如果您有更多的提交,只需将数字1增加到您希望看到的提交差异。

此命令将获取Git父提交哈希:

git log -n 2 <commit-hash>

之后,gitdiff工具<commithash><parentcommithash>

例子:

bonnie@bonnie ~/ $ git log -n 2 7f65b9a9d3820525766fcba285b3c678e889fe3

commit 7f65b9a9d3820525766fcba285b3c678e889fe3b
Author: souparno <souparno.majumder@gmail.com>
Date:   Mon Jul 25 13:17:07 2016 +0530

CSS changed to maintain the aspect ratio of the channel logos and to fit them properly.

commit c3a61f17e14e2b80cf64b172a45f1b4826ee291f
Author: souparno <souparno.majumder@gmail.com>
Date:   Mon Jul 25 11:28:09 2016 +0530

The ratio of the height to width of the channel images are maintained.

在此之后

git difftool 7f65b9a9d3820525766fcba285b3c678e889fe3b c3a61f17e14e2b80cf64b172a45f1b4826ee291f
git difftool COMMIT^ <commit hash>

如果您配置了difftool,也可以使用。

请参阅此处如何配置difftool。或此处的手册页。

此外,您可以使用git diff树--no commit id--name only-r<commit hash>来查看在给定的提交哈希中更改/提交了哪些文件。