Squashing commits in git

So you are done with your project. You take a look at your commit history and cannot help but feel ashamed of multiple identical commit messages you have there. I know you are not to blame. Come on, why does setting up Heroku config have to be so darn treacherous?

Say no more, git has you covered even in your lowliest moments. Follow these simple steps to squash those redundant commit messages into one. Afterwards, boldly share your masterpiece with the world!


  1. Head to your project folder and type `$ git log`.
  2. Search for a group of identical commits and copy the ID of the commit before the oldest commit of interest (I hope that isn’t confusing). The ID should look like this: 07942d773b99fd6fe7a51afefd361df0312d0954.
  3. Quit the git log screen with by tapping `q`.
  4. On the terminal type `$ git rebase -i {commit ID}` and tap enter.
  5. You should be taken to a text editor (basically VIM) where the erring commit messages would be at the top and a list of commands you can enter would be placed at the bottom of the page.
pick c97a40e [Bug] Fix serving of bower components on heroku
pick 2cc5dd1 [Bug] Fix serving of bower components on heroku
pick 3dd68b5 [Bug] Fix serving of bower components on heroku
pick f912ae8 [Bug] Fix serving of bower components on heroku
pick 73eda89 [Bug] Fix serving of bower components on heroku
pick aaa2a96 [Bug] Fix serving of bower components on heroku

6. Switch to insert mode by pressing `i`. Leave the first line as is but replace pick as you see above with “squash” for the redundant links. Do not modify commit messages of a different title!

7. When you are done, press the colon (‘:’) key and `wq’ to save the file.

8. This takes you to a new vim page. There, edit the first commit message if necessary and delete the other commit messages.

9. Again, type the colon(‘:’) and `wq` to save and continue rebase.

Thats it. You could do this for all other redundant commits. Remember to forcefully push changes next time you push to remote with:

`$ git push -f origin [name of branch]`.

If you have any issues following through, please let me know in the comments below. Thanks for reading.
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.