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:
- Place the cursor at the beginning of the line with the first commit you want to squash
- Enter visual block mode (CTRL-V)
- Select all the rows you want to squash
- Hit 'c' and type 'squash' to replace the 'pick' command
- Press ESC to apply that change to all the selected rows
What worked for me:
:%s/pick/squash/g
to replace all instances ofpick
withsquash
+ manually updating the first one to be apick
.