Question

Right, this may sound like a bit of an odd question, but I think I've done something stupid.

I had two different branches (with a very small number of changes), and I wanted to merge SOME changes from one to the other. So, in Git Extensions, I went Commands > Merge Branches.

Unfortunately, rather than giving me the option to manage merge conflicts, it just went through it automatically after hitting OK. As this was not what I wanted, I attempted to find a way to try and roll it back.

What I ended up doing was selecting the last Commit for one of the branches (before the merge, but the latest Commit out of either branch) and hard resetting back to it.

Rather than restoring things to their previous state (ie the merge not having taken place), I am instead left with what appears to be the single red line in git extensions of both branches each being the same, AND the latest version (ie post-merge). I can still switch between the two branches, but there's no apparent difference between them.

So this is basically what I wanted to do (I apologise for the crudity of this diagram, I'm not really sure how best to display it):

Branch 1
   x---------------y
          \
           \ 
   x--------x------y
Branch 2

I have changes I wanted to merge from Branch 1 into Branch 2, but I wanted to keep them both separate, AND I didn't want to merge ALL the changes.

Can my mistakes I've made above be reverted? And what would have been the correct way to do this?

Was it helpful?

Solution

It sounds like you did a reset of both branches back to the same commit. You should reset each branch to a commit before the merge on that branch.

So, in this diagram

Branch1
   A------
          \
           \ 
   B--------C------D
Branch2

do

git checkout Branch1
git reset --hard A
git checkout Branch2
git reset --hard B

After that you could use git cherry-pick to pick specific commits from one branch and copy them on the other.

So, to create this diagram

Branch1
   E-----G---------I
          \
           \ 
   F--------H
Branch2

do

git checkout Branch2
git cherry-pick G
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top