Skip to content

Instantly share code, notes, and snippets.

@titenkov
Last active October 24, 2024 15:12
Show Gist options
  • Save titenkov/fb933e971143b76977deb07827ecf7a9 to your computer and use it in GitHub Desktop.
Save titenkov/fb933e971143b76977deb07827ecf7a9 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
@wichopy
Copy link

wichopy commented Mar 24, 2023

you da real mvp

@seanbecker15
Copy link

this is great 🔥

@mredigonda
Copy link

What worked for me: :%s/pick/squash/g to replace all instances of pick with squash + manually updating the first one to be a pick.

@aapatni
Copy link

aapatni commented Jun 3, 2024

goat

@mstudio
Copy link

mstudio commented Oct 24, 2024

Perfect, thanks for sharing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment