Git: How to rebase to a specific commit?

You can avoid using the --onto parameter by making a temp branch on the commit you like and then use rebase in its simple form:

git branch temp master^
git checkout topic
git rebase temp
git branch -d temp

Use the "onto" option:

git rebase --onto master^ D^ D

OR

git rebase --onto <commitB> <commitA> <commitD>

The 3 last arguments mean:

  • destination (new-parent, here it's commitB),
  • start-after (current-parent, parent of first commit to be moved),
  • and end-inclusive (last commit to be moved).

You can even take a direct approach:

git checkout topic
git rebase <commitB>