Search code examples
gitversion-controlrebasegit-rebase

Git: How to rebase to a specific commit?


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?


Solution

  • 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