Git Interactive Rebase

A feature often grows through messy local commits: experiments, fixes after review, formatting passes, and small corrections. That history can be useful while working but noisy once the branch is ready to share.

Interactive rebase lets you rewrite a local run of commits into a clearer shape before other people depend on it.

Squashing Local Commits

First inspect the recent history:

git log --oneline

Count the commits you want to rewrite, then start an interactive rebase:

git rebase -i HEAD~N

Git opens an editor with one line per commit. To squash several commits into one, keep the first commit as pick and mark later commits as squash or s.

pick   abc1234 add parser
squash def5678 fix parser edge case
squash fed4321 rename test fixture

After saving, Git opens another editor for the combined commit message. The result is one commit where there used to be several.

Where It Breaks

Interactive rebase rewrites commit identities. That is fine for local cleanup, but it is risky after the commits have been shared and other branches are based on them.

The practical rule is simple: use interactive rebase freely on local work; coordinate before rewriting published history.

Design Check

Before squashing, ask:

Interactive rebase is not only a command. It is an editing pass over the story the repository will preserve.