14 / 57 · 17 Git & Version Control · Rebase vs Merge← prev⊞ allnext →☰ Read as one page
2.6Interactive Rebase: Cleaning Up Before a PR
Interactive rebase lets you rewrite, combine, reorder, or drop commits before sharing them.
# Rebase the last 4 commits interactively
git rebase -i HEAD~4
This opens an editor with your commits:
pick abc1234 WIP: start login tests
pick def5678 fix typo
pick ghi9012 WIP: more login tests
pick jkl3456 finish login tests
Change the actions:
pick abc1234 WIP: start login tests
fixup def5678 fix typo # Merge into previous, discard message
squash ghi9012 WIP: more login tests # Merge into previous, combine messages
pick jkl3456 finish login tests
Common actions:
pick: Keep the commit as-issquash: Combine with the previous commit, edit the combined messagefixup: Combine with the previous commit, discard this commit's messagereword: Change the commit messagedrop: Remove the commit entirely
When QA engineers should use interactive rebase:
- Combine multiple "WIP" or "fix typo" commits into a single logical commit
- Reword vague commit messages like "fix tests" to something descriptive
- Remove commits that were debugging experiments (e.g., "add console.log")
- Reorder commits so related changes are grouped together