Appearance
Interactive Rebase Quick Reference
Core command
git rebase -i HEAD~N # Rebase last N commits
git rebase -i <base> # Rebase onto base (usually main)
git rebase -i --root # Rebase entire historyTodo list operations
| Short | Full | Effect |
|---|---|---|
p | pick | Use commit as-is |
r | reword | Keep content, edit message |
e | edit | Stop to amend content or split |
s | squash | Combine into previous, merge messages |
f | fixup | Combine into previous, discard message |
x | exec | Run shell command (non-zero = stop) |
d | drop | Remove commit entirely |
b | break | Stop rebase for manual inspection |
Useful flags
git rebase -i --autosquash # Auto-place fixup! commits after targets
git rebase -i --exec "cmd" # Run command after every commit
git rebase -i --rebase-merges # Preserve merge topology
git rebase -i --empty=drop # Drop commits that become empty
git rebase -i --update-refs # Update stacked branch refs
git rebase -i -X theirs # Auto-resolve conflicts with rebased sideRecovery
git rebase --abort # Abort and return to original state
git rebase --continue # After resolving conflict or editing
git rebase --skip # Skip the current commit
git reset --hard ORIG_HEAD # Recovery after completed rebaseCI patterns
# Gate every commit with lint
git rebase -i --exec "npm run lint" origin/main
# Auto-squash and verify
git rebase -i --autosquash --exec "npm test" mainConfig
ini
[rebase]
autoSquash = true
autoStash = true
updateRefs = true
missingCommitsCheck = warn
stat = true