Get the difference between two branches in Git
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.
2 Solutions collect form web for “Get the difference between two branches in Git”
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.
This is a simple git diff
git diff --name-only SHA1 SHA2
Where SHA1/2 are the hashes of the 2 commits at the top of each branch.