Git rebase with --onto
implements the idea:
cut and paste from start commit
B
to end commitE
and put it "onto" commitO
.
If you have a situation where somebody made a somebranch
PR against master
but it should have been against another branch, like this:
o---o---o somebranch
/
o---o---o---B---o master
\
o---o---o---o---o haskell-updates
(Note the commit where somebranch
branches off master
is called B
for "merge base").
Then you can switch the the somebranch
to be based on haskell-updates
instead by using git rebase
with --onto
.
In this case, it is:
cut and paste from start commit
B
to end commitsomebranch
and put it "onto" commithaskell-updates
.
So we run (while being on somebranch
):
git rebase B somebranch --onto haskell-updates
o---o---o---B---o master
\
o---o---o---o---o haskell-updates
\
o---o---o somebranch
Then you can switch the base in Github. (You can also do this before.)
This approach is a short-cut for going onto haskell-updates
and using git cherry-pick
for every single commit in somebranch
manually (and then renaming the result of that back to somebranch
).