Interactive Rebase
Interactive rebase lets you reorganize, edit, squash, reorder, or drop commits before sharing them. It is particularly useful for cleaning up a feature branch before review.
Commands in an interactive rebase include pick, reword, edit, squash, fixup, and drop.
Clean Up Recent Commits
git rebase -i HEAD~4
# Example todo:
# pick abc123 Add login form
# squash def456 Fix login form
# reword 789abc Add validation
# pick 012def Add testsThe interactive todo list determines how Git should replay the selected commits.
Key Takeaways
Interactive rebase is useful for local history cleanup.
squashcombines commits while allowing message editing.fixupcombines commits while discarding the fixup commit's message.
Knowledge Check
What does squash do in an interactive rebase?