How to rebase with squashed commits

Viewed 173

I had something that looks like this

                6---7 (currentBranch)
               /
      3---4---5---8 (initialBranch)
     /
1---2 (master)

I squash merged initialBranch into master, so now master looks something like

1---2---9 where commit '9' is commits 3+4+5+8 squashed together

My ultimate goal is to rebase currentBranch in the remote repo to look something like

          6---7 (currentBranch)
         /
1---2---9

What are the series of commands I need to run to accomplish this?

1 Answers

If you still have the commit "merge base" between the original initialBranch and currentBranch, meaning commit 5, you can do a rebase --onto:

git rebase --onto master 5 currentBranch

That would replay any commit after 5 (so 6 and 7) on top of the current master.

Related