Git: Grafting Commits (Simple And Sweet)

There are a lot posts sharing many degrees of complexity of how to rebase/graft/replace a bunch of commits, but this is the process given the simplest case:

git rebase --onto <new parent> <old parent>

Given the parent commit of the series of commit, move them to a different parent.

So, given these commits under BRANCH1:

AAA (HEAD)
AAB
AAC
AAD

..and these commits under BRANCH2:

BBA
BBB
BBC
BBD

…in order to place AAA->AAB->AAC on top of BBA->BBB->BBC:

git rebase --onto BBA AAD

Standard rev-parse rules apply (you can use branches/tags instead of revisions).

Leave a comment