Interactive Rebase - Tidy Your History
git rebase -i
Interactive rebase rewrites your recent (local) commits - squash, reorder, reword, or drop them before sharing.
$ git rebase -i HEAD~4 # edit the last 4 commits
You get an editor listing the commits with a verb per line:
| Verb | Action |
|---|---|
pick | Keep the commit as-is |
reword | Keep changes, edit the message |
squash | Merge into the previous commit (combine messages) |
fixup | Like squash but discard this message |
drop | Delete the commit entirely |
| (reorder lines) | Reorder the commits |
Tip: The classic use: turn "add feature / fix typo / oops / actually works" into one clean commit withsquash/fixupbefore opening a PR.git commit --fixup=<hash>+git rebase -i --autosquashautomates the ordering.
Danger: Interactive rebase rewrites commit IDs. Only do it on local, unpushed commits (or a branch only you use). Never rewrite shared history others have based work on.