当我执行gitdiffCOMMIT时,我看到了提交和HEAD之间的变化(据我所知),但我希望看到单个提交所做的变化。
我还没有在diff/log上找到任何明显的选项来提供输出。
当我执行gitdiffCOMMIT时,我看到了提交和HEAD之间的变化(据我所知),但我希望看到单个提交所做的变化。
我还没有在diff/log上找到任何明显的选项来提供输出。
当前回答
首先使用,
git log #to list all
Or
git log -p -1 #last one commit id
复制提交id。
现在我们使用两种方法列出特定提交的更改,
方法1:
git diff commit_id ^#提交id类似于1c6a6000asad012
方法2:
git show commit_id
For example: git show 1c6a600a
其他回答
检查文件更改的更简单方法(示例)
# 1. Checkout a branch and see the list of commits
git log --oneline -5
# > Output
9b9b1f8 (HEAD -> master) Updated ABC
d58e5da chore: Added files
5a4aa2c chore: Added my pipeline
bb2b0b7 feat: Added ABC
473f711 feat: Added ZYX
# 2. Pick a commit hash and check which files were modified
git show --stat --oneline d58e5da
# > Output
d58e5da chore: Added versioning files
Someabcfile | 18 ++++++++++++++++++
myfolder/file.py | 19 +++++++++++++++++++
myfolder/file.js | 7 +++++++
myfolder/file.txt | 1 +
4 files changed, 45 insertions(+)
# 3. Pick a file to check the differences
git show d58e5da myfolder12/file.py
或者,从列表中检查一次提交中的所有文件差异:
git show d58e5da
我喜欢下面的命令来比较特定的提交和上次提交:
git diff <commit-hash>^-
例子:
git diff cd1b3f485^-
Use:
git show <commit_sha>
这将向您展示该承诺中的内容。只需在两个提交SHA-1散列之间放置一个空格,就可以完成范围。
git show <beginning_sha> <ending_sha>
如果您经常重新设置基础,这非常有用,因为您的功能日志都是一行的。
如果您想查看最后3次提交,可以使用HEAD语法
git show HEAD~3 HEAD
一些答案漏掉了一个特例。如何查看根提交所做的更改,因为它没有父/祖先。
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)
我在windows 10上运行的是Git 2.6.1.windows.1版本,所以我需要对Nevik的答案稍作修改(用波浪号代替插入符号):
git diff COMMIT~ COMMIT
另一个选项是引用插入符号:
git diff "COMMIT^" COMMIT