Squashing commits using an interactive rebase

When I work on a local branch, I prefer to commit in small increments with a few comments on what I did in the commits; however, as these commits do not build or pass any test requirements, I cannot submit them for review and verification one by one. I have to merge them in my branch, and still, cherry picking my fix would require me to cherry-pick twice the number of commits, which is not very handy.

What we can do is rebase and squash the commits into a single commit or at least a smaller number of commits.

Getting ready

To get started with this example, we need a new branch, namely rebaseExample3, that tracks origin/stable-3.1. Create the branch with the following command:

$ git checkout -b rebaseExample3 ...

Get Git: Mastering Version Control now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.