Interactive Rebase: Squash, Fixup and Autosquash
Combine related changes
A draft watering commit says Water every 3 day. A later correction adds the plural s. Those patches belong together, while README is independent. Squash and fixup fold changes into the preceding todo commit, not necessarily its original parent. Keep a rescue branch and inspect the series before editing. The squash and fixup scenarios in the guide are separate repositories, each with three private commits.
Choose the message policy
For squash, leave Describe watering as pick and change Fix plural unit to squash. Git proposes a combined message for editing; keep a meaningful message. For plain fixup, change the correction to fixup instead, retaining the target message and discarding the correction message. Both incorporate the correction patch. Do not mark the first todo item squash or fixup: there is no preceding commit in the todo to fold into.
git branch rescue-featuregit rebase -i --no-autostash --no-update-refs --no-autosquash mainMark a fix as you work
Autosquash can move a marked correction next to its target and change its action. In the separate autosquash scenario, first create Describe watering, then Add README. Stage the plural correction and create a fixup commit targeting the watering commit, here HEAD~1 before committing. Inspect the generated todo, since similar subjects can be ambiguous and dependencies may matter. The marker alone does not fold anything until rebase runs.
printf "Water every 3 days\n" > notes.txtgit add -- notes.txtgit commit --fixup=HEAD~1git branch rescue-featuregit rebase -i --autosquash --no-autostash --no-update-refs mainCheck content and messages separately
All three scenarios end with two commits after main, with the corrected notes in the first and README in the second. The final tree matches the corresponding rescue branch. Plain fixup keeps Describe watering; the squash fixture retains both messages because its controlled editor accepts the proposed text. In real work, edit that message for clarity. Advanced amend and reword fixup variants change message handling; they are not needed for this exercise. Practice: explain why deleting a todo line is not the same as fixup.
git rev-list --count main..HEADgit log -1 --format=%B HEAD~1git show HEAD~1:notes.txtgit diff --exit-code rescue-feature HEADCheck Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Interactive Rebase: Squash, Fixup and Autosquash — knowledge check
Reason about private history editing and verification.
What does plain fixup retain?
What does squash normally propose?
When does --fixup=REV fold a correction?
Why inspect an autosquash todo?
What is wrong with fixup on the first todo line?