0

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!

Jeff P.
  • 2,214
  • 3
  • 15
  • 38
  • Unless you have a pretty ancient Git (e.g., 1.7.x), the `git status` output and the subsequent complaint about unmerged files don't seem to mix properly. If you *do* have such an ancient Git, this all makes sense. – torek Nov 09 '17 at 23:45
  • @torek I was able to revert this change by using `git reset --hard master`, credit to this post: https://stackoverflow.com/questions/2452226/master-branch-and-origin-master-have-diverged-how-to-undiverge-branches I think the issue I'm having is using `git rebase` correctly to reparent. – Jeff P. Nov 10 '17 at 00:05
  • In general you want to be very careful with `git reset --hard`. What I should have just asked is: *what version of Git are you running?* – torek Nov 10 '17 at 00:14
  • @torek git --version git version 2.14.3.windows.1 – Jeff P. Nov 10 '17 at 00:20
  • OK, then I'm puzzled, as `git status` should have shown the merge-in-progress that was blocking the `git pull`. This may be some Windows-specific thing. – torek Nov 10 '17 at 00:26

1 Answers1

2

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
Marina Liu
  • 32,805
  • 4
  • 48
  • 60
  • This was exactly what I needed! This is an excellent explanation and I do appreciate you taking the time in giving the details. I hope this helps others who run into this issue as well! – Jeff P. Nov 10 '17 at 15:57