Git: How to rebase to a specific commit?

Ondra Žižka picture Ondra Žižka · Oct 12, 2011 · Viewed 212.2k times · Source

I'd like to rebase to a specific commit, not to a HEAD of the other branch:

A --- B --- C          master
 \
  \-- D                topic

to

A --- B --- C          master
       \
        \-- D          topic

instead of

A --- B --- C          master
             \
              \-- D    topic

How can I achieve that?

Answer

Adam Dymitruk picture Adam Dymitruk · Oct 12, 2011

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