Reputation: 3004
I just finished working on 2 separate develop branches that were originally branched off of the main Master branch. Here is the flow I used in branching off of the Master Branch to create these 2 develop branches:
Master
|--> DevelopBranch1
|
-->DevelopBranch2
So originally I created DevelopBranch1
by branching from Master
. Then I created DevelopBranch2
by branching off of DevelopBranch1
. My reasoning behind this decision was because DevelopBranch2
depended on new changes I made within DevelopBranch1
.
I finished making changes to DevelopBranch1
. Since DevelopBranch2
did not originally branch off of Master
, I now want to do a few things:
1) Merge DevelopBranch1
into Master
2) Reparent DevelopBranch2
into Master
3) Merge DevelopBranch2
into Master
4) Archive DevelopBranch1
I was successful in Merging DevelopBranch1
into Master
ok by using SourceTree by checking out Master
and Merging it with the latest commit from DevelopBranch1
.
When I got to step 2, this is where I ran into issues. I used the following git command to Reparent:
git checkout master
git rebase --onto DevelopBranch2
After the rebase command, I noticed within SourceTree that the latest commit from Master
got moved to the latest commit within DevelopBranch2
.
At this point, I tried Merging Master
into DevelopBranch2
. After using this Merge and running git status
, I got the following message
On branch master
Your branch and 'origin/master' have diverged,
and have 5 and 7 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
I then ran git pull
and got this message:
git pull
error: Pulling is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.
This is where I'm currently stuck.
Any help would be greatly appreciated!
Upvotes: 0
Views: 221
Reputation: 38096
It's caused by the wrongly used command git rebase --onto DevelopBranch2
. Let's illustrate by below graphs:
After step1 (merge DevelopBranch1
into Master
), the command history is:
...---A---B---C-------J Master
\ /
D---F---G DevelopBranch1
\
H--I DevelopBranch2
If you use the command git rebase --onto DevelopBranch2
, it will reset the current branch Master
to DevelopBranch2
as below:
...---A---B---C-------J
\ /
D---F---G DevelopBranch1
\
H--I DevelopBranch2, Master
For you situation, you should use git rebase --onto Master DevelopBranch1 DevelopBranch2
instead. Then it will reparent the DevelopBranch2
to Master
branch as what you expected.
First, you should reset your Master
branch to the merge commit (the commit merged DevelopBranch1
into Master
), Then execute the command for step2 again. The commands used as below:
git checkout Master
git reset --hard <merged commit id>
git rebase --onto Master DevelopBranch1 DevelopBranch2
git push origin DevelopBranch2 -f
Then the step2 will be execute correctly (as below graph). And you can continue to execute step3 and step4.
H'---I' DevelopBranch2
/
...---A---B---C-------J Master
\ /
D---F---G DevelopBranch1
Upvotes: 2