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

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


当前回答

一些答案漏掉了一个特例。如何查看根提交所做的更改,因为它没有父/祖先。

Both

git diff<root_commit>^<root_commit>

and

git diff<root_commit>~<root_commit>

抛出错误。

$git diff 27e521ca73a46b2d3a28568dc49fced81e46aaea~ 27e521ca73a46b2d3a28568dc49fced81e46aaea
fatal: ambiguous argument '27e521ca73a46b2d3a28568dc49fced81e46aaea~': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

git diff<root_commit>^!

显示diff btw根提交和HEAD。像这样:

$ git diff 27e521ca73a46b2d3a28568dc49fced81e46aaea^!
diff --git a/file1.txt b/file1.txt
new file mode 100644
index 0000000..80f3f1a
--- /dev/null
+++ b/file1.txt
@@ -0,0 +1,5 @@
+Create the first file.
+
+Add some placeholder text to first file.
+
+
diff --git a/file2.txt b/file2.txt
new file mode 100644
index 0000000..66e494f
--- /dev/null
+++ b/file2.txt
@@ -0,0 +1,6 @@
+This is the second file.
+
+It has an uncommited commit.
+
+We use it to demo default `git diff` behaviour.
+

(这些是所有提交对我的根提交和HEAD所做的更改)。

对于根提交

我只发现

git show--color--prett=格式:%b<root_commit_hash>

作品

像这样:

$ git show --color --pretty=format:%b 27e521ca73a46b2d3a28568dc49fced81e46aaea

diff --git a/README b/README
new file mode 100644
index 0000000..12a04f0
--- /dev/null
+++ b/README
@@ -0,0 +1,6 @@
+# git-diff-demo
+
+This repo documents the demo of the git diff command.
+We will have options, and use cases.

(我的根提交仅添加了README)

其他回答

您可以在git的特定地址上单击每次提交以查看如果您使用工具提交,您可以通过展会历史记录

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

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

要通过提交查看作者和时间,请使用gitshowCOMMIT。这将导致如下情况:

commit 13414df70354678b1b9304ebe4b6d204810f867e
Merge: a2a2894 3a1ba8f
Author: You <you@you.com>
Date:   Fri Jul 24 17:46:42 2015 -0700

     Merge remote-tracking branch 'origin/your-feature'

如果您想查看哪些文件已更改,请使用上面“合并”行中的值运行以下命令:git diff--stat a2a2894 3a1ba8f。

如果要查看实际差异,请运行git-stat a2a2894 3a1ba8f。

要查看特定COMMIT哈希的差异,其中COMMIT是提交的哈希:

gitdiffCOMMIT~COMMIT将向您展示COMMIT的祖先和COMMIT之间的区别。有关命令和gitrevisions的详细信息,请参阅gitdiff的手册页。

或者,gitshowCOMMIT也会做类似的事情。(提交的数据,包括其diff,但不包括合并提交的数据。)请参阅gitshow手册页。

(gitdiffCOMMIT也会显示COMMIT和头部之间的区别。)

另一种可能性:

git log -p COMMIT -1