git-rebase(1) does exactly that.
$ git rebase -i HEAD~5
git awsome-ness [git rebase –interactive] contains an example.
- Don’t use
git-rebaseon public (remote) commits. - Make sure your working directory is clean (
commitorstashyour current changes). - Run the above command. It launches your
$EDITOR. - Replace
pickbeforeCandDbysquash. It will meld C and D into B. If you want to delete a commit then just delete its line.
If you are lost, type:
$ git rebase --abort