Interactive Rebase: squash, edit, reorder

Interactive rebase is the editor for your recent history. By the end of this lesson you'll squash messy work-in-progress commits into clean ones, reword and reorder commits, drop mistakes, and pause to edit a commit's content — all before you share your work.

Learn Interactive Rebase: squash, edit, reorder in our free Git course — a beginner-friendly interactive lesson with worked examples, a practice exercise and…

Part of the free Git course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.

1️⃣ Opening an Interactive Rebase

git rebase -i HEAD~3 opens an editor with a todo list of your last three commits, oldest at the top . Each line starts with an action word (default pick ) followed by the commit. You change the action words, optionally reorder the lines, then save and close to apply.

2️⃣ The Actions

A quick tour: pick keeps a commit as-is; reword keeps it but edits the message; squash folds it into the commit above and combines messages; fixup does the same but discards this commit's message; edit pauses so you can amend its content; drop deletes it. Reorder commits just by reordering the lines.

3️⃣ Squashing Commits

The classic use is collapsing several messy commits into one before a pull request. Keep the first as pick and mark the rest squash (or fixup to drop their messages). On saving, Git opens a second editor so you can write one clean combined message.

Your turn. Squash three commits into one and reword it. Fill in the two blanks.

📋 Quick Reference

No commands given this time — just the plan. Turn four messy commits into a clean, shareable set.

Practice quiz

What does open?

  • A merge tool
  • The remote settings
  • An editable 'todo' list of commits with actions
  • A diff viewer

Answer: An editable 'todo' list of commits with actions. Interactive rebase opens an editor listing the commits and the action to take on each.

In , what does HEAD~3 select?

  • The last 3 commits to replay/edit
  • The 3rd commit only
  • 3 branches
  • The first 3 commits ever

Answer: The last 3 commits to replay/edit. HEAD~3 picks the three most recent commits for the interactive rebase.

What does the action do?

  • Deletes the commit
  • Merges it
  • Renames the branch
  • Keeps the commit as-is

Answer: Keeps the commit as-is. pick keeps the commit unchanged — it's the default action for each line.

What does (s) do?

  • Deletes a commit
  • Combines a commit into the previous one, keeping BOTH messages to edit
  • Reverses a commit
  • Splits a commit

Answer: Combines a commit into the previous one, keeping BOTH messages to edit. squash folds the commit into the one above and lets you combine the messages.

How does (f) differ from ?

  • fixup combines into the previous commit but DISCARDS the fixup's message
  • fixup keeps both messages
  • fixup deletes the commit
  • There is no difference

Answer: fixup combines into the previous commit but DISCARDS the fixup's message. fixup melds the change into the prior commit and throws away its message.

What does (r) do?

  • Rewrites the code
  • Deletes the message
  • Keeps the commit but lets you change its message
  • Reorders commits

Answer: Keeps the commit but lets you change its message. reword keeps the commit's changes but prompts you to edit its message.

What does (e) let you do?

  • Only change the message
  • Pause at that commit so you can amend its content or split it
  • Delete the commit
  • Skip the commit

Answer: Pause at that commit so you can amend its content or split it. edit stops the rebase at that commit so you can amend its contents.

How do you DROP a commit entirely in interactive rebase?

  • Use 'pick'
  • Use 'squash'
  • Use 'reword'
  • Use the 'drop' action or delete its line

Answer: Use the 'drop' action or delete its line. Mark the line drop (or remove the line) to discard that commit.

How do you REORDER commits in an interactive rebase?

  • You can't reorder
  • Rearrange the lines in the todo list
  • Use git reorder
  • Change their hashes

Answer: Rearrange the lines in the todo list. Reordering the lines in the todo editor reorders the commits when applied.

Is interactive rebase safe to use on already-pushed, shared commits?

  • Yes, always
  • Only with fixup
  • No — like all rebasing, it rewrites history and shouldn't touch shared commits
  • Only on main

Answer: No — like all rebasing, it rewrites history and shouldn't touch shared commits. Interactive rebase rewrites history, so the golden rule still applies: don't rewrite shared commits.