peco peco - 4 months ago 16
Git Question

Rebase part of branch to a commit

My

master
looks like this:

A --- B --- C (master)


I branched from
B
and made some changes on branch
1
:

A --- B --- C (master)
\
\-- D --- E --- F (1)


Then I branched from
F
and made some changes on branch
2
:

A --- B --- C (master)
\
\-- D --- E --- F (1)
\
\-- G --- H --- I (2)


Then I applied my changes on
1
onto
master
by merge squashing
D
,
E
,
F
into
master
, where
K
is the result of merge squashing
D
,
E
and
F
:

A --- B --- C --- K (master)
\ / | \
\-- D --- E --- F (1)
\
\-- G --- H --- I (2)


Then, I want to rebase
G
,
H
,
I
onto
K
, so that it looks like this:

A --- B --- C --- K (master)
\
\-- G' --- H' --- I' (2)


Is there a way to do this?

Answer

Sure, like usual.

git rebase --onto master f branch2