获取Git中两个分支之间的差异 [英] Get the difference between two branches in Git
问题描述
我做了以下(我简化了这个与现实的比较):
所以,实际差异原始分支和 Branch1 之间仅为 File2 的修改。 获得分支机构之间的实际差异并将其放入 Branch2 中。一般来说,我想摆脱没有必要添加/删除 File1 的历史记录。 解决方案
假设您从分支 master
开始。然后你可以这样做:
git diff master Branch1> ../patchfile
git checkout Branch2
git apply ../patchfile
或者,如果您的目标是重写历史记录,那么您可以使用互动式重新绑定来压扁提交。
I did following (I simplified this comparing to a reality):
- created a branch Branch1, switched to it
- added file File1 and modified existing file File2 and commited this
- figured out that I don't need File1, removed it and commited this
So, the actual difference between original branch and Branch1 is only modification of File2.
I want to get this actual difference between branches and put in Branch2. Generally speaking, I want to get rid of not necessary history of adding/removing File1.
Let's assume that you started on the branch master
. Then you can do:
git diff master Branch1 > ../patchfile
git checkout Branch2
git apply ../patchfile
Alternatively, if your goal is to rewrite history, then you could use an interactive rebase to squash commits.
这篇关于获取Git中两个分支之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!