Wednesday, June 7, 2023

Play with Git SQUASH



Git squash refers to the act of merging multiple commits into a single one. This can be accomplished using Git's "Interactive Rebase" feature, which allows you to perform this action at any given moment. Squashing commits is typically performed when merging branches.

Below are the syntaxes when you perform squash in the git branch

  1. git log --oneline
    • Enter letter 'q' to exit from the current line
  2. git rebase -i HEAD~3
    • Change sub commit from pick to s
    • Then press ESC and type :wq to exit
    • Then again change the commit message and press ESC, type :wq to exit
  3. git push -f

If something went wrong in above steps use git rebase --abort to cancel the process and start again.