Take the 2-minute tour ×

I want to do something similar to what the standard interactive rebase does, but I want to use it just to clean up my branch's history and not pull in any updates from another branch. So, I want to keep the 'branching point' the same. For example, if my branch is B1:

--O--O--O--O--O--O------O--O----O--O   master
       O---O--x--x--x--O--O--x--x--O   B1

In the above diagram, O is a clean commit and x is a messy commit I want to squash with the ones before it and maybe change the commit message. With a normal interactive rebase on master I could get this:

                                     O---O--X--O--O--X--O   B1

Where X is messy commits squashed together with a cleaned up commit message. But how can I get the below?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

You can rebase on any commit, not just on master's HEAD. Let's say your branch point of B1 is 12345, then you can interactively rebase B1 on that commit with

# make sure you are on B1
$ git checkout B1

$ git rebase -i 12345

Then cleanup the history.

See git help rebase for more pointers.

share|improve this answer
add comment

The 'git rebase' documentation deals exactly with your case:



   then the command

       git rebase --onto topicA~5 topicA~3 topicA

   would result in the removal of commits F and G:


   parameter can be any valid commit-ish.
share|improve this answer
add comment

Your Answer


