Search code examples
gitbranchrebasebranching-and-merging

I rebased interactively on the master branch, so a feature branch now looks like it starts well before it did. How can I fix this?


I had a master branch and a feature branch:

A --- B --- C --- D --- E Master
             \
              F - G --- H Feature

Then I rebased the master branch interactively, such that C changed (and become C'. Now the latest commit in common between the branches is B:

A --- B --- C' --- D --- E Master
       \
         C - F --- G --- H Feature

How I can get back to what I really meant? That is, where the feature branch only has the relevant commits in it, not the old ones which I have subtly changed:

A --- B --- C' --- D --- E Master
             \
               F - G --- H Feature

TIA.


Solution

  • Easy. Rebase your feature branch onto C':

    git rebase --onto C' C Feature
    
    

    The C Feature part selects the commits from C to Feature (head) (i.e. F, G and H), the --onto C' part rebases them onto C'.

    You can add the interactive -i switch if you want to see what it will do before it does it.