bbuser
bbuser

Reputation: 928

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?

Upvotes: 10

Views: 2390

Answers (3)

Alex
Alex

Reputation: 253

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

Upvotes: 2

Matthias Benkard
Matthias Benkard

Reputation: 15759

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

Upvotes: 1

kan
kan

Reputation: 28951

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.

Upvotes: 8

Related Questions