Git Squash

Git - Squash


Git Squash commit

 To squash in Git means to combine multiple commits into one. You can do this at any point in time (by using Git's "Interactive Rebase" feature), though it is most often done when merging branches.

Please note that there is no such thing as a stand-alone git squash command. Instead, squashing is rather an option when performing other Git commands like interactive rebase or merge.

Squash using interactive rebase

In the below example, the last 3 commits are combined into one commit using git-rebase.

  •    touch test.java
  •    git status
  •    touch test1.java
  •    touch test2.java
  •    git add .
  •    git commit -m "test.java" test.java
  •    git commit -m "test1.java" test1.java
  •    git commit -m "test2.java" test2.java
  •    git log --oneline
  •    git rebase -i HEAD~3

change pick to squash



rewrite the commit history by adding # infront of test1.java and test2.java 

Comments