Tough scenario is when you have to merge two branches of a solution with so many differences that one cannot simply be merged into the other. In this scenario I use SourceTree as GIT GUI client, KDiff3 linked to SourceTree as external merge tool to create DIFF patch from phase 2.0 set of commits and apply it to phase 3.0 branch. Bear in mind the two branches have many differences and I cannot just merge both in one merge action.
So let's begin...
Open the SourcThree and create patch from Actions.
You can select the desired commits you'd like to merge into the other branch. Creating such a patch can be done with GIT command, but since I am a Microsoft developer guy :) I will use the visuals way.
At the bottom of the screen can be seen the files to be included in the patch file and from which to which commit.
So once the .diff file is exported on the HDD, I swap to the phase 3.0 branch on which I will apply the patch . So in the menu Actions -> Apply Patch
Here is where the fun begins. The following red merge issue appears notifying that there are merge conflicts.
When the screen is closed a new file or files to be merged can be seen in the commit area.
To resolve the merge I use KDIFF3 set as external tool for the SourceTree. Launch the external tool and resolve the conflict lines.
To continue we have to move this commit forward from menu Actions -> Continue Rebase. however I got the following error from SourceTree:
git -c diff.mnemonicprefix=false -c core.quotepath=false -c "sequence.editor='C:\Program Files (x86)\Atlassian\SourceTree\stree_gri'" -c "core.editor='C:\Program Files (x86)\Atlassian\SourceTree\stree_gri'" rebase --continue
It looks like git-am is in progress. Cannot rebase.
Completed with errors, see above.
I am not going give up now :). After quick search on the net it turned I can workaround this error and do the following:
Go to Actions -> Open in Terminal. Then type
git am --resolved
Then minimize the terminal and look into the SourceTree commits. New files for merge should appear as uncommitted. Resolve the next conflicts and then get back to the terminal and execute
git am --resolved
I had a case where my merge process stuck at already resolved so I escaped to the next conflict with:
git am --skip
Then resolve the next change....
Once all conflicts are resolved, then they can be seen int he SourceTree history explorer. Not in proper order, but there.
Note be careful when merge to get the most resent code since the commits are not ordered ascending by date in the diff patch. There may be a way to be done, but I didn't get so far.
If the rebase process is not fully completed is can be aborted from the SourceTree terminal:
git am --abort
I had to perform of course additional after merge actions to align everything , but this at least helped me to get from very tough merge situation.