当我执行gitdiffCOMMIT时,我看到了提交和HEAD之间的变化(据我所知),但我希望看到单个提交所做的变化。
我还没有在diff/log上找到任何明显的选项来提供输出。
当我执行gitdiffCOMMIT时,我看到了提交和HEAD之间的变化(据我所知),但我希望看到单个提交所做的变化。
我还没有在diff/log上找到任何明显的选项来提供输出。
当前回答
git difftool COMMIT^ <commit hash>
如果您配置了difftool,也可以使用。
请参阅此处如何配置difftool。或此处的手册页。
此外,您可以使用git diff树--no commit id--name only-r<commit hash>来查看在给定的提交哈希中更改/提交了哪些文件。
其他回答
此命令将获取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>来查看在给定的提交哈希中更改/提交了哪些文件。
对我来说,这很好
git show COMMIT --compact-summary
显示下一个信息
输出扩展头信息的浓缩摘要,例如diffstat中的文件创建或删除(“new”或“gone”,如果是符号链接,可选“+l”)和模式更改(“+x”或“-x”分别用于添加或删除可执行位)。信息放在文件名部分和图形部分之间。暗示--stat。
一些答案漏掉了一个特例。如何查看根提交所做的更改,因为它没有父/祖先。
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 diff(1)的手册页:
git diff [options] [<commit>] [--] [<path>…]
git diff [options] --cached [<commit>] [--] [<path>…]
git diff [options] <commit> <commit> [--] [<path>…]
git diff [options] <blob> <blob>
git diff [options] [--no-index] [--] <path> <path>
使用中间的第三个:
git diff [options] <parent-commit> <commit>
同样从同一手册页底部的示例部分:
$ git diff HEAD^ HEAD <3>
比较上次提交和上次提交之前的版本。
诚然,它的措辞有点混乱,但也不会那么混乱
将最近的提交与之前的提交进行比较。