How to Squash Commits in Git

Easy Guide to Squash Commit with Problem Solving

Firda Sahidi
iOSnesia
2 min readApr 1, 2020

--

Photo by Christoper Gower on Unsplash

Squash commits could be one of many tricky problems in iOS Development (and another project too). In this article, I want to give you a simple tutorial on how to squash commit with problem-solving tips.

Step-by-step Squash

1. Checkout to branch that you want to squash.

2. Check how many commits that you have in that branch.

3. Squash it.

4. Pick which commits that you want to squash. If you want to squash that commit, type squash before commit number. If you want to choose commit that squashed into, type pick before commit number. It should look like this.

5. Press esc, then type :wq and press enter.

6. Type :wq and press enter again.

7. Force push your changes.

Problem-shooting

If you had merge conflict errors when squashing, don’t panic. Just type this.

It will open an external merge tool, you can fix errors easily in that tool. Just scroll down the merge tool and find errors there. There is a red line in the scroll indicator if you have an error in which line. After finish fixing your error, just press cmd+s and exit the merge tool. Then continue your squash.

If you have more than two commits to be squashed, sometimes you have to do this things more than once. Don’t panic because it’s normal.

Squash Tips

Last but not least, a little tip from me is, always squash after you commit. Because the more commits you to have to squash into one commit, the conflict rate will be increasing too. Let squash be one of your habits after commit.

--

--

Firda Sahidi
iOSnesia

Indonesian iOS Developer with 6+ years of professional experiences. Recent MSc Fintech Graduate from University of Edinburgh. Check out my list below!