Skip to content

Instantly share code, notes, and snippets.

@igorb
Forked from titenkov/vim-visual-blocks.md
Created October 19, 2022 10:47
Show Gist options
  • Save igorb/fdfd22f58034611329fb44a515d9ea62 to your computer and use it in GitHub Desktop.
Save igorb/fdfd22f58034611329fb44a515d9ea62 to your computer and use it in GitHub Desktop.
Use Vim visual blocks during interactive git rebase

Sometimes, when rebasing interactively with git, we need to squash a sequence of commits in a branch.

For example, we need to transform this:

pick 0253dc894f bumped
pick 5a1e86933c remove dependency
pick bffoffb395 memberships rpc resource
pick 222fabf5e0 rpc membership service
pick 726a2f9a10 remove crypto logic

To this:

squash 0253dc894f bumped
squash 5a1e86933c remove dependency
squash bffoffb395 memberships rpc resource
squash 222fabf5e0 rpc membership service
pick 726a2f9a10 remove crypto logic

Doing that manually one by one can be a bit tiresome, so if you're using Vim you can use visual blocks:

  1. Place the cursor at the beginning of the line with the first commit you want to squash
  2. Enter visual block mode (CTRL-V)
  3. Select all the rows you want to squash
  4. Hit 'c' and type 'squash' to replace the 'pick' command
  5. Press ESC to apply that change to all the selected rows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment