如何让git diff只显示两次提交之间的差异,而不包括中间的其他提交?
当前回答
假设你有这个
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的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
直接在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
在比较提交中阅读更多信息
为了比较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添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式
- git pull -rebase和git pull -ff-only之间的区别
- GitHub -致命:无法读取用户名https://github.com':没有这样的文件或目录