# Interactive Rebase `git rebase -i` lets you rewrite commit history by reordering, squashing, editing, or dropping commits. ```bash # Rebase the last 3 commits git rebase -i HEAD~3 ``` The editor opens with a list of commits (oldest first). Each line starts with a command: | Command | Short | Effect | |---------|-------|--------| | `pick` | `p` | Keep the commit as-is | | `reword` | `r` | Keep the commit but edit its message | | `edit` | `e` | Pause to amend the commit (content + message) | | `squash` | `s` | Meld into previous commit, combine messages | | `fixup` | `f` | Meld into previous commit, discard this message | | `drop` | `d` | Remove the commit entirely | ## Common workflows - **Squash before merging:** Combine WIP commits into a clean history - **Reword:** Fix a typo in a commit message - **Reorder:** Move related commits together - **Edit:** Split a commit into smaller ones (use `git reset HEAD~` during the pause) ## Caveats - Never rebase commits that have been pushed to a shared branch - If something goes wrong: `git rebase --abort`