Git squash - taking series of commits to a single commit

This is a little trick from git if you need to make your commits nice and clean.

If you need to take the above three commits to a single nice commit you can use the git squash,
so let's take the all the 3 commits to the first WIP commit, which is
b011ff7 WIP test case 1
Type below command in your terminal.
git rebase -i HEAD~3
Here HEAD~3 means you are going to squash the first 3 commits. Now a text editor will open looks like in below image.

Each line represents a commit (in chronological order, the latest commit will be at the bottom).
To transform all these commits into a single one, change the file to this and save and exit
This means, you take the first commit, and squash the following onto it. If you remove a line, the corresponding commit is actually really lost.
your editor will open once more to ask for a commit message for the squashed commit and change the commit message as you wish. Finally, you will get your changes to one single commit.

Thank you !!!


Post a Comment