Skip to content
gitrep
Library

b7d0a44guide1 min read

Interactive rebase without fear

Squash, reorder, and reword commits before review, with a safety net in place.

Published

A clean history is a gift to reviewers. Interactive rebase lets you shape a branch into a sequence of commits that each make sense on their own.

Set a safety net

sh
git branch backup/$(git branch --show-current)

Rewrite the branch

sh
git rebase -i --autosquash main
  • pick keeps a commit as is.
  • reword keeps the change and edits the message.
  • fixup folds a commit into the one above it and drops its message.
  • Reorder lines to reorder commits.

Commit small fixes with git commit --fixup <ref> as you go, and --autosquash will line them up for you.

  1. Undo almost anything in GitA calm guide to reflog, reset, revert, and restore — and how to choose the right one when something goes wrong.Guide
  2. Find and replace across a repositoryA safe one-liner with ripgrep and sed, with a dry run first.Snippet