Git Squash to Speed Up Your Workflow
I am a big fan of work-in-progress (WIP) commits. When I am working through a prototype or a spike, and need to do some experimentation with the code, I use WIP commits like they are save points in a game. These points act like milestones, and allow me to keep working with the confidence that I can always go back to an earlier working state. I use these aliases for the job:
1 2 3
When I get the work into a good state, I
wip it (I may even sing 🎶 When a problem comes along… you must whip it! 🎶). If I want to grab the last WIP commit from the branch, I
popwip to pop the last commit off the stack and put the last bunch of changes back into my working directory.
However, when I have been prototyping for a while, making
wip commits as I go, popping a bunch of commits off the stack gets a little unwieldy. Until now I used an interactive rebase to rewrite my branch’s commit history. For example:
For this git history, I would rebase on sha 83bfc47:
1 2 3 4 5 6 7 8 9 10
I would proceed to
reword the first and
fixup the rest, writing a thoughtful and all-encompassing commit message to convey the intention behind this chunk of work. Then I discovered
git merge --squash
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
All of the changes I have made on that branch since it diverged from master have been added to the index. I am free to either chunk up the changes into different commits (with commit messages that are more descriptive than WIP), or add them all to a single commit.
Hello merge --squash!