Squash, reword, and reorder commits with git rebase -i (interactive rebase)

domain: git-scm.com · 8 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. Ensure your working tree is clean, then run `git rebase -i <base>` where <base> is the commit you want to rewrite on top of (e.g. the branch point, or `HEAD~N` for the last N commits). Use `git rebase -i --root` to rewrite every commit including the first.
  2. Git opens an editor listing each commit as a line like `pick <short-sha> <subject>`, oldest first. Change the verb per line: `pick` (keep as-is), `reword` (edit the message), `edit` (stop to amend the commit), `squash` (merge into the previous commit, combining messages), `fixup` (merge into previous, discarding its message), or `drop` (remove).
  3. Reorder lines freely to change commit order; save and close the editor to start the rebase.
  4. For each `squash`/`fixup`, Git replays the commits; for `squash` it opens another editor to combine the commit messages, for `fixup` it applies without prompting.
  5. On a conflict, Git stops and shows markers. Resolve the files, then `git add <paths>` and `git rebase --continue` to resume; inspect the rewritten result with `git log`.
  6. If something goes wrong, `git rebase --abort` returns your branch to its original state, or `git rebase --quit` aborts without resetting the working tree/index.
  7. Notify collaborators: interactive rebase rewrites commit hashes, so only use it on commits that are not pushed/shared (or force-push explicitly afterward).
  8. Official docs: https://git-scm.com/docs/git-rebase

Known gotchas

Related routes

Fold follow-up fixes into earlier commits with git commit --fixup and git rebase --autosquash
git-scm.com · 7 steps · unrated

Give your agent this knowledge — and 17,000+ more routes

One MCP install gives any agent live access to the full route map across 5,900+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans