Part IV: Chapter 4.10

Interactive Rebase

Pick, squash, fixup, reword, drop.

git rebase -i opens a to-do list of commits and lets you rewrite history any way you like before sharing it. Squash noisy WIP commits, drop mistakes, reorder, rename — then replay the cleaned-up sequence as new commit objects.

The Interactive To-Do List

Change the action on each commit, then hit Run rebase to see the resulting history. Try: squash the WIP commit, fixup the auth fix, drop the typo.

rebase-todo (oldest → newest)

keep as-is
a1b2Add auth module
keep as-is
c3d4WIP: auth — broken
keep as-is
e5f6Fix broken auth
keep as-is
g7h8Add user profiles
keep as-is
i9j0typo in readme
keep as-is
k1l2Polish profiles UI

Result (run rebase to see)

Waiting...

The Six Actions

pick

Keep the commit exactly as-is. Default for every commit. If you don't change anything, nothing changes.

reword

Keep the commit's changes but pause to let you edit the commit message. Useful for fixing typos in messages before sharing.

squash

Meld this commit into the one above it. Git combines both commit messages and lets you edit the result. Good for grouping related commits.

fixup

Like squash, but silently discards this commit's message. Perfect for "fix typo" or "oops" commits that don't deserve a message.

drop

Remove this commit entirely from history. The changes it introduced disappear. Use with care — this is permanent once shared.

edit

Pause the rebase at this commit so you can amend it — split it into multiple commits, add files, change content. Then 'git rebase --continue'.

Running It

HEAD~N tells Git how far back to go. Git opens your $EDITOR with the to-do file — edit the actions, save, close, and Git executes the plan.

Terminal
$# Interactively rebase the last 6 commits:
$git rebase -i HEAD~6
# Your editor opens with:
pick a1b2 Add auth module
pick c3d4 WIP: auth — broken
pick e5f6 Fix broken auth
pick g7h8 Add user profiles
pick i9j0 typo in readme
pick k1l2 Polish profiles UI
$# Edit it to:
pick a1b2 Add auth module
squash c3d4 WIP: auth — broken
fixup e5f6 Fix broken auth
reword g7h8 Add user profiles
drop i9j0 typo in readme
pick k1l2 Polish profiles UI
$# Save and close → Git executes, opens editor for messages
Successfully rebased and updated refs/heads/feature.