I did following (I simplified this comparing to a reality):
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.
To compare the current branch/commit, press Ctrl+Shift+B or choose the option shown in the image below & then select the branch &/or commit to compare. Bonus: To compare in GitHub web, press Ctrl+Shift+C. It only shows differing commits, and if you click on a commit it will show the changed of that commit.
Another way to do this is to right-click on a branch and select the "Diff against current" context menu command (current refers to the branch you are currently working on). This will give you the diff between the head commits of the two branches.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With