All Articles

Squashing multiple commits in Vim with visual block command in Terminal

Screenshot of many commits in Terminal

Steps to squash multiple commits in Terminal using Vim

  1. git rebase -i HEAD~5 (5 or however many commits you had, differing from master)
  2. Put the cursor highlight on the SECOND commit using your arrow keys.
  3. To enable visual block, do CRTL + V
  4. Use DOWN arrow keys to highlight pick for each commit (not including the commit you want to squash the other commits into).
  5. Press f for fixup (or s for squash - this depends on the command you want to use)
  6. Exit visual mode by pressing Esc.
  7. When you do :wq to exit Vim, the fixups will be filled in for you automatically, removing the need to do it manually for each commit.

More reading: Atlassian Git Rebase