Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git - merge difference of branches

I have three branches A, B and C. B is regularly merged into C.

          o---o---o A
         /
--------o---o---o---o---o---o B
         \       \       \   \
          o---o---o---o---o---o C

Now I want to merge the changes I did in C, but without the merges from B, on top of A. What is the easiest way to do this in git?

like image 787
bbuser Avatar asked Sep 29 '11 08:09

bbuser


3 Answers

Use the git rebase.

First, rebase your C on top of B:

git checkout C
git checkout -b rebasedC #Let's do a new branch for it also, just in case
git rebase B

it will place all C commits on to of B. Now we want transplant branch rebasedC from B to A:

git rebase --onto A B rebasedC

So, now you have your C-commits on top of A in the rebasedC branch. Now you can fast-forward your A to it:

git checkout A
git merge rebasedC
git branch -d rebasedC# I don't think you would need it.

That's all, I hope.

like image 162
kan Avatar answered Nov 06 '22 12:11

kan


If i understand correctly, you want to take some commits from C into A.

If that´s the case, why don´t you "cherry-pick" them? It can lead to conflicts, but i think its your best chance :)

http://schacon.github.com/git/git-cherry-pick.html

http://schacon.github.com/git/user-manual.html#reordering-patch-series

like image 27
Alex Avatar answered Nov 06 '22 12:11

Alex


You can try cherry-picking C's non-merge patches. Be prepared to handle merge conflicts. :)

like image 32
Matthias Benkard Avatar answered Nov 06 '22 13:11

Matthias Benkard