如何让git diff只显示两次提交之间的差异,而不包括中间的其他提交?


当前回答

我的别名设置在~/。git的Bashrc文件:

alias gdca='git diff --cached' # diff between your staged file and the last commit
alias gdcc='git diff HEAD{,^}' # diff between your latest two commits

其他回答

为了比较12345和abcdef作为补丁的两个git提交,可以使用diff命令作为

diff <(git show 123456) <(git show abcdef)

假设您想查看提交012345和abcdef之间的差异。以下内容可以达到你的目的:

$ git checkout 012345
$ git cherry-pick -n abcdef
$ git diff --cached

你可以简单地将2个提交传递给git diff,就像这样:

-> git diff 0da94be  59ff30c > my.patch
-> git apply my.patch

从Git 2.19开始,你可以简单地使用:

Git range-diff rev1 -比较两个提交树,从它们的共同祖先开始

或 Git range-diff rev1~..rev1 rev2 ~ . . rev2 -比较2个提交所带来的变化

git diff <a-commit> <another-commit> path

例子:

git diff commit1 commit2 config/routes.rb

它显示了两次提交之间在该文件上的差异。