当我执行git diff COMMIT
命令时,我看到的是该提交和HEAD之间的更改(就我所知),但我想要查看单个提交所做的更改。
我没有在diff
/log
上找到任何明显的选项可以给我这个输出。
当我执行git diff COMMIT
命令时,我看到的是该提交和HEAD之间的更改(就我所知),但我想要查看单个提交所做的更改。
我没有在diff
/log
上找到任何明显的选项可以给我这个输出。
另一种可能性:
git log -p COMMIT -1
我喜欢使用如下命令来比较一个特定的提交和它的上一个提交:
git diff <commit-hash>^-
例子:
git diff cd1b3f485^-
你可以使用 git diff HEAD HEAD^1
命令查看与父提交的差异。
如果你只想要查看文件列表,则需要添加 --stat
选项。
diff
命令的方式是:我需要更改文件以从提交“HEAD”到提交“HEAD^1”? - brainplotgit difftool COMMIT^ <commit hash>
git diff-tree --no-commit-id --name-only -r <commit hash>
来查看在给定的提交哈希中更改/提交的文件。git difftool -d
比普通的 git difftool
更易用。 - ks1322要查看提交的作者和时间,请使用git show COMMIT
。这将会得到类似下面的结果:
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
。
git --stat a2a2894 3a1ba8f
。我认为您的意思是 git diff a2a2894 3a1ba8f
,否则会出现 unknown option: --stat
。 - 林果皞git show COMMIT
已经显示了普通提交的更改集,但对于合并提交不会显示。 - Mecki检查完整的更改内容:
git diff <commit_Id_1> <commit_Id_2>
检查仅更改/添加/删除的文件:
git diff <commit_Id_1> <commit_Id_2> --name-only
注意: 如果您想在提交之间检查差异,您不需要放置提交ID。
git show
即可。git show HEAD
# 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 <root_commit>^..<root_commit>
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>^!
展示了 根提交 和 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 --pretty=format:%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文件。