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


当前回答

直接在GitHub上查看差异;您可以- https://github.com/<username>/<reponame>/compare/<commit1>..<commit2> .

commit1和commit2可以是分支名或commit哈希值

为例:

比较gs/add-explicit-paths-to-js-files分支和gs/add-history-helper - https://github.com/twbs/bootstrap/compare/gs/add-explicit-paths-to-js-files..gs/add-history-helper 比较commit 75e09b1c0f5ae5f51078c7a25fe36d892c5cfcfe和585146a6a7aa70faf25442d7d28636ce57e29588 - https://github.com/twbs/bootstrap/compare/75e09b1c0f5ae5f51078c7a25fe36d892c5cfcfe..585146a6a7aa70faf25442d7d28636ce57e29588

在比较提交中阅读更多信息

其他回答

假设你有这个

A
|
B    A0
|    |
C    D
\   /
  |
 ...

你要确保A等于A0。

这样就可以了:

$ git diff B A > B-A.diff
$ git diff D A0 > D-A0.diff
$ diff B-A.diff D-A0.diff

那么这个呢:

git diff abcdef 123456 | less

如果你想要在运行中比较许多不同的差异,将它管道到less是很方便的。

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

例子:

git diff commit1 commit2 config/routes.rb

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

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

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

直接在GitHub上查看差异;您可以- https://github.com/<username>/<reponame>/compare/<commit1>..<commit2> .

commit1和commit2可以是分支名或commit哈希值

为例:

比较gs/add-explicit-paths-to-js-files分支和gs/add-history-helper - https://github.com/twbs/bootstrap/compare/gs/add-explicit-paths-to-js-files..gs/add-history-helper 比较commit 75e09b1c0f5ae5f51078c7a25fe36d892c5cfcfe和585146a6a7aa70faf25442d7d28636ce57e29588 - https://github.com/twbs/bootstrap/compare/75e09b1c0f5ae5f51078c7a25fe36d892c5cfcfe..585146a6a7aa70faf25442d7d28636ce57e29588

在比较提交中阅读更多信息