Squashing By Merging With The –Squash Option

Git can combine the different changes into a single commit. The “–squash” option helps you to can merge multiple commits into a single commit.

Git combines all the changes into a single commit and applies it on top of the target branch.

Following are the steps to use “–squash”.

Step 1: Create and Switch to a new branch.

Create a branch that you want to merge into which is also called the target branch. After creating a branch change to that new branch by using the below command.

git checkout new_branch_name

Step 2: Merge the branch.

Know to merge the branch by using the “–squash” option including the git merge option. As shown below.

git merge --squash <Branch>

Step 3: Resolve and Commit the changes.

In between you may face some merge conflict issues which to be resolved manually. After resolving the issue commit the changes to the local repository where this commit will have a single message with all the commit history. 

Step 4: Push the changes to the remote repository.

By using the git push command push the recent commit to the remote repository.

The commit history will be simplified by using the “–squash” option which makes it cleaner. 

Git – Squash

Pre-requisite: Git

Squashing combines multiple commits into a single commit based on your commit history. With the help of squashing you can clean your branch history and can maintain an organized commit timeline. It is used before pulling requests or merging feature branches.

Similar Reads

What is Git Squashing?

Assume you are building a project using Git as your version control. You released Version One after that you wanted to add new features for the Version Two release and you even fixed a few bugs found in Version One. You had plenty of commits piled up after your 1st release. Is there a way to merge all the commits after 1st release into a single commit? yes, it is possible using squash. Squash is one of the useful and powerful features available in the git rebase command’s interactive mode....

Git Squash-Merge Command Line

By using the git squash-merge command you can combine multiple commits into a single commit. After using the git squash command your repository will be clean and organized manner....

When To Squash Commits?

Now we have a repository called GFG_VIDEO, which is an open-source video conferencing tool. GFG_VIDEO has released the 1st version of their tool with basic features such as peer-to-peer video calling and messages with the tag R_V1 (Green colored). After the R_V1 release team GFG_VIDEO started to add new features such as creating groups, group video calls, and fixing minor bugs from R_V1 such as call drops, etc. Now GFG_VIDEO is ready for their new release R_V2....

How To Squash Commits?

The below image shows we have 3 commits: Initial commit, Commit 2, and Version 1 Release. We’ve successfully released the 1st version (R_V1) of the GFG_VIDEO tool. After R_V1 new features are added and minor bugs are fixed from the previous release and the tool is ready for its 2nd release R_V2....

Squashing By Interactive Mode

Upon entering the above command we’ll get an interactive editor with all our selected commits which is where we’ll be performing squash....

Squashing By Merging With The –Squash Option

Git can combine the different changes into a single commit. The “–squash” option helps you to can merge multiple commits into a single commit....

Git Squash Last 2 Commits

By using the interactive rebase feature you can squash the last two commits....

Git Squash vs Rebase

Git Squash Git Rebase You can combine multiple commits into a single commit. Applies commits on top of the different base commits. After using git squash your commit history will be more clean and organized. You can form a new branch by using previous commits.  Must be done on private branches.  Rebasing can be done on a feature branch or shared branch. By using squishing you can maintain clean and logical commit history. By using rebase command you can keep your branch up to date....

Frequently Asked Questions

1.  Is squashing commits a good idea?...

Contact Us