Squash Git Commitsby Gaurav Jassal on 2014-03-14
Git is amazing and I recently learnt an awesome trick from one my colleague. If you need to combine you commits to one larger one, you can use git rebase to do that. The rebase command has some awesome options available in its —interactive (or -i) mode, and one of the most widely used is the ability to squash commits or combine commits.
For example if you want to squash last 3 commits, run this command.
git rebase -i HEAD~3
This will take you to a log screen where you can all of you 3 commits. Now you need to change pick to squash in your commits and save it.
In the next window you will edit your commit message.So, now you can ignore commit messages for your previous commit and add a new commit message and save. The final screen will show you that your rebase command have was completed.
Once rebase completes you will see this screen.
Try your logs again
You will now see that your all three commits are combined to one commit.