lak*_*tak 1364 git version-control diff git-diff
当我这样做时,git diff COMMIT
我看到了提交和HEAD之间的变化(据我所知),但我希望看到单个提交所做的更改.
我没有在diff/log上找到任何明显的选项,它会给我输出.
Nev*_*nel 1759
要查看特定COMMIT
哈希的差异 :
git diff COMMIT~ COMMIT
会告诉你这个COMMIT
祖先和祖先之间的区别COMMIT
.有关命令和gitrevisions有关表示法及其朋友的详细信息,请参阅git diff的手册页. ~
或者,git show COMMIT
将做一些非常相似的事情.(提交的数据,包括它的差异 - 但不适用于合并提交.)请参阅git show联机帮助页.
Von*_*onC 466
如" 使用其父级的git提交的差异的简写? "中所述,您还可以使用git diff
:
git diff COMMIT^!
Run Code Online (Sandbox Code Playgroud)
要么
git diff-tree -p COMMIT
Run Code Online (Sandbox Code Playgroud)
使用git show,你需要(为了专注于diff)来做:
git show --color --pretty=format:%b $COMMIT
Run Code Online (Sandbox Code Playgroud)
该COMMIT
参数是提交上下的:
甲commit对象或一个对象可以被递归地解除引用到一个提交对象.以下是所有承诺,ishes:提交对象,标签对象指向一个commit对象,指向一个指向commit对象等标签对象标签对象
请参阅gitrevision"SPECIFYING REVISIONS"以引用commit-ish.
另请参阅" Git中树的含义是什么? ".
Lak*_*han 308
您也可以尝试这种简单方法:
git show <COMMIT>
Run Code Online (Sandbox Code Playgroud)
Pep*_*rez 49
对我来说这很好用
\ngit show COMMIT --compact-summary\n
Run Code Online (Sandbox Code Playgroud)\n显示下一个信息
\n\n\n输出扩展头信息的简明摘要,例如文件创建或删除(“新”或“消失”,如果\xe2\x80\x99是符号链接,则可选“+l”)和模式更改(“+x”或“-” x”分别用于在 diffstat 中添加或删除可执行位)。该信息位于文件名部分和图形部分之间。意味着--stat。
\n
Moh*_*med 30
首先使用获取提交ID,
git log #to list all
Run Code Online (Sandbox Code Playgroud)
要么
git log -p -1 #last one commit id
Run Code Online (Sandbox Code Playgroud)
复制提交ID.
现在我们使用两种方法列出特定提交的更改,
方法1:
git diff commit_id^! #commit id something like this 1c6a6000asad012
方法2:
git show commit_id
For example: git show 1c6a600a
Run Code Online (Sandbox Code Playgroud)
Iwn*_*nay 29
git show <commit_sha>
Run Code Online (Sandbox Code Playgroud)
这将向您展示该提交中的内容.我想你可以通过在两个提交sha之间放一个空格来做一个范围.
git show <beginning_sha> <ending_sha>
Run Code Online (Sandbox Code Playgroud)
如果您经常变基因,这非常有用,因为您的功能日志将全部连续.
小智 25
从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>
Run Code Online (Sandbox Code Playgroud)
使用中间的第3个:
git diff [options] <parent-commit> <commit>
Run Code Online (Sandbox Code Playgroud)
同样来自同一手册页,位于底部的示例部分:
$ git diff HEAD^ HEAD <3>
Run Code Online (Sandbox Code Playgroud)
比较上次提交和最后一次提交之前的版本.
不可否认,它的措辞有点令人困惑,因为它不那么令人困惑
将最近的提交与之前的提交进行比较.
Ale*_*lex 25
我通常这样做:
git diff HEAD~1
Run Code Online (Sandbox Code Playgroud)
显示有关最后一次提交的更改。如果您有更多提交,只需将数字1增加到要查看的提交差异数即可。
Mic*_*ser 21
以下似乎可以胜任这项工作; 我用它来显示合并带来了什么.
git whatchanged -m -n 1 -p <SHA-1 hash of merge commit>
Run Code Online (Sandbox Code Playgroud)
Irs*_*shu 10
您可以使用git diff HEAD HEAD^1
父提交来查看差异.
如果您只想查看文件列表,请添加该--stat
选项.
git difftool COMMIT^ <commit hash>
Run Code Online (Sandbox Code Playgroud)
如果您配置了difftool,也可以使用.
看到这里如何配置difftool 或手动页面点击这里
此外,您可以使用git diff-tree --no-commit-id --name-only -r <commit hash>
以查看在提交提交哈希中更改/提交的文件
我喜欢下面的命令来比较特定的提交及其最后的提交:
git diff <commit-hash>^-
Run Code Online (Sandbox Code Playgroud)
例:
git diff cd1b3f485^-
Run Code Online (Sandbox Code Playgroud)
要检查完整的更改:
git diff <commit_Id_1> <commit_Id_2>
Run Code Online (Sandbox Code Playgroud)
仅检查更改/添加/删除的文件:
git diff <commit_Id_1> <commit_Id_2> --name-only
Run Code Online (Sandbox Code Playgroud)
注意:为了检查差异而不在两者之间提交,您不需要放置提交 ID。
# 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
Run Code Online (Sandbox Code Playgroud)
# 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(+)
Run Code Online (Sandbox Code Playgroud)
# 3. Pick a file to check the differences
git show d58e5da myfolder12/file.py
Run Code Online (Sandbox Code Playgroud)
或者,也可以从列表中检查单个提交内的所有文件差异:
git show d58e5da
Run Code Online (Sandbox Code Playgroud)
通过提交使用来查看作者和时间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'
Run Code Online (Sandbox Code Playgroud)
如果要查看哪些文件已更改,请使用上面"合并"行中的值运行以下命令git diff --stat a2a2894 3a1ba8f
.
如果你想看到实际的差异,请运行 git --stat a2a2894 3a1ba8f
获取提交中更改的文件列表:
git show --name-only commit_id
注意:以上命令不适用于合并 ID。
要获取合并提交 ID 中更改的文件列表:
git log -m -1 --name-only commit_id
查看提交中
特定文件的更改:git show commit_id:src/path/to/that/file
小智 5
一些答案遗漏了一个特殊情况。如何查看根提交所做的更改,因为它没有父级/祖先。
两个都
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>...]'
Run Code Online (Sandbox Code Playgroud)
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.
+
Run Code Online (Sandbox Code Playgroud)
(这些是我的根提交和 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.
Run Code Online (Sandbox Code Playgroud)
(我的根提交仅添加了自述文件)