Interactive Rebase: Reorder and Reword Private Commits
Edit a private story, not shared history
Interactive rebase lets you review and edit a sequence of commits before replay. Imagine a garden notebook with three independent changes: watering, light, and README. You want the light change first and a clearer watering message. Unlike ordinary rebase onto a new base, this exercise edits a series on the same base. Work only in a disposable private branch; do not rewrite commits other people depend on. Start with the reorder scenario in lab-fixtures/chapter21-guide.md.
Preserve the original tip
Inspect status and the oldest-first list. The base main is excluded from the todo. If any valuable uncommitted changes exist, stop and preserve them separately; a branch only preserves committed history. Create rescue-feature once, before rewriting. Disable automatic ref updates so that the rescue reference is not moved, and disable autostash and autosquash for this manual exercise. Git uses a sequence editor for the todo and a commit message editor for reword. Use a configured editor you understand.
git status --shortgit log --reverse --oneline main..HEADgit branch rescue-featuregit rebase -i --no-autostash --no-update-refs --no-autosquash mainRead the todo from top to bottom
The initial order is Watering draft, Add light detail, Add README. Move the entire light line above the watering line; change only the watering action to reword. Keep the actual hashes supplied by Git. Save and close, then replace the watering message with Document watering clearly in the second editor. Pick replays a commit, reword changes its message, edit stops for changes, drop omits a patch. Reordering dependent commits can conflict or break intermediate snapshots. The fixture uses independent paths.
# Illustrative only: edit the real todo in your editor# pick <light-id> Add light detail# reword <watering-id> Watering draft# pick <readme-id> Add READMEVerify the new order
The expected messages are Add light detail, Document watering clearly, Add README. The final tree matches the rescue branch, but the tip ID changes. A different parent or message changes a commit identity; untouched prefix commits may be reused. If a rebase is still in progress and you want to cancel, git rebase --abort restores the original branch but discards resolution work from the active operation. Once complete, inspect the rescue branch instead. Practice: predict why the first new commit still contains Water every 3.
git log --reverse --format=%s main..HEADgit diff --exit-code rescue-feature HEADgit show HEAD~2:notes.txtCheck Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Interactive Rebase: Reorder and Reword Private Commits — knowledge check
Reason about private history editing and verification.
Which commits appear in the ordinary linear todo for rebase -i main?
What does reword change?
Why preserve rescue-feature and pass --no-update-refs?
What can happen when dependent commits are reordered?
Which order does the todo use in the fixture?