This page looks best with JavaScript enabled

Merge more than one Commits before Pushing

 ·   ·  ☕ 2 min read

When I first came to know about this, I was like:

What is Squashing

The process of merging commits together is called squashing. There are many commands to do the same thing, but I will discuss the one I learned. There’s a read more section below if you want to know more about this topic.

Don’t go far Deep

One thing to keep in mind, before we start is, we should avoid merging our pushed commits. It will create a problem to other developers if you’re working in a team, and things will kinda mess up.

Codes and Explanations

Ariejan has already explained this in deep, so I will not do the same here but will do it for my reference. For merging last 3 commits, we can pass:

git rebase -i HEAD~3

This will open up your default editor configured with git with the following content:

pick hash Commit 1
pick hash Commit 2
pick hash Commit 3

The commits appear from older to newer. We’re probably gonna merge commit 2 & 3 into commit 1. In our code editor what we’ll do is replace pick from commit 2 & 3 lines to squash.

Sorry for the syntax highlighting. wordpress.com is preventing me from adding most external services like gist and all which has javascript embed (Twitter is working though).

What are your thoughts on this post? How do you squash your changes? I’m eager to know. Please leave comments.

Further Reading

Share on

Santosh Kumar
WRITTEN BY
Santosh Kumar
Fullstack Developer at Method Studios