git rebase --onto
Here is how to rebase
develop
onto 2 chained feature branches (branch1 and branch2).branch1 branch2 | | A----B----C----D / o----o----o----o | develop
You rebase develop on branch1 and end up with this second graph
branch2 | A----B----C----D / o----o----o----o----A'---B' | | develop branch1
Option 1 Assuming that you know that branch2 was 2 commits ahead of branch1, cf. first graph. This will rebase ]branch2~2, branch2] (ie. ]B, D] in other words commits C and D onto branch1
git checkout branch1
git rebase develop # rebase develop onto branch1
git rebase --onto branch1 branch2~2 branch2Option 2 This one is generic and does not assume that you know, before the rebase, the number of commits branch2 is ahead of branch1.
git checkout branch1
git rebase develop
git rebase --onto branch1 ORIG_HEAD branch2You then end up with this graph.
branch2 | o----o----o----o----A'---B'----C----D | | develop branch1
last updated september 2018