Split a Private Git Commit into Focused Changes
Recognize a mixed-purpose commit
A commit named Update notes and light changes two independent tracked files. A later commit adds README. Splitting the first commit makes each change reviewable on its own. Use the split scenario in the guide, not a root commit or a merge. Confirm the branch is private and clean, record its original tip, and start interactive rebase. Mark the first todo entry edit and leave the README entry pick. Git pauses at the selected commit, usually with detached HEAD.
git status --shortgit branch rescue-featuregit rebase -i --no-autostash --no-update-refs --no-autosquash mainMove HEAD back without discarding files
At the edit stop, inspect HEAD to confirm it is the intended combined commit. Mixed reset to its parent resets HEAD and index, leaving the working files as they are. In this disposable case both edited tracked files become unstaged. Do not substitute --hard; it would overwrite the very changes you need. If the state is not the expected one, stop before resetting.
git show --stat HEADgit reset --mixed HEAD^git status --shortgit diffBuild two focused snapshots
Stage notes.txt alone, inspect the staged diff and commit. At this point light.txt must still be modified only in the working tree; the recorded light content remains Indirect light. Stage and commit light.txt separately. These steps form replacement commits, with the current configured authorship; do not assume original metadata or signatures are automatically retained. Check that the working tree is clean before continuing.
git add -- notes.txtgit diff --cachedgit commit -m "Clarify watering"git show HEAD:light.txtgit add -- light.txtgit diff --cachedgit commit -m "Clarify light"git status --shortgit rebase --continueInspect the resulting series
The expected sequence is Clarify watering, Clarify light, Add README. Final content matches the original two-commit sequence. Verify each intermediate change by comparing parent and child. If you abort while editing, the original branch returns; the new split work is not automatically preserved by the rescue reference. If you want to keep such work, preserve it first using an appropriate separate reference or external copy. Practice: which snapshot first contains the new light detail?
git log --reverse --format=%s main..HEADgit diff --name-only HEAD~3 HEAD~2git diff --name-only HEAD~2 HEAD~1git diff --exit-code rescue-feature HEADCheck Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Split a Private Git Commit into Focused Changes — knowledge check
Reason about private history editing and verification.
Which todo action pauses for splitting?
What does mixed reset HEAD^ do at the intended edit stop?
Why not use hard reset for this split?
After committing only notes.txt, what remains?
How do you finish after both split commits and a clean status?