Split a Git commit into smaller commits
Use interactive rebase to stop at a commit, unstage its changes, and rebuild a reviewable series without losing the original tree.
To split an older, ordinary commit, stop at it with interactive rebase, reset to its parent while preserving the working files, and commit the changes in smaller groups. Start with a clean checkout and keep a backup branch before rewriting history.
Stop at the commit
Replace a1b2c3d with the commit you intend to split:
git status
git branch backup-before-split
git rebase -i 'a1b2c3d^'
Change that commit's pick to edit in the todo list. Git replays up to it and stops with its changes committed. The parent expression requires a non-root commit; this recipe is for a linear segment of history, not an arbitrary merge topology.
Rebuild smaller commits
git reset --mixed 'HEAD^'
git add -- src/login.js
git commit -m "Implement login endpoint"
git add -- src/login.test.js
git commit -m "Test login endpoint"
The mixed reset preserves the working tree and clears staging back to the parent. Newly introduced files become untracked, so include them explicitly when rebuilding the commits.
For changes within one tracked file, use git add -p, inspect git diff --cached, then commit the selection. Repeat until all intended changes are committed. If you want patch staging for a newly added file, git add -N -- path/to/new-file marks it as intent-to-add first.
git status
git rebase --continue
Do not leave a final git add -p selection uncommitted before continuing. Test each resulting commit where practical; a clean final tree alone does not prove that each intermediate commit works.
Resolve conflicts or abandon the split
Later commits may depend on the original structure. Resolve conflicts, stage the resolutions, and run git rebase --continue. Use git rebase --abort to return to the pre-rebase branch state; save any newly created work you want to retain before aborting.
For the latest non-root commit, you can use the mixed-reset and recommit steps directly without starting a rebase. To select a root commit in an interactive rebase, use --root, but the HEAD^ reset above cannot split a root because it has no parent; handle that case with a separate reconstruction plan.
Publishing the result
Splitting changes commit IDs and rewrites descendants. Coordinate before rewriting any published branch, including a personal PR branch someone may have fetched. A lease-protected push can publish an agreed rewrite, but it is not permission to overwrite collaborators' work. Protected branches may disallow it.
Each new commit can have a new message. If all you need is a message correction, use reword instead of splitting.
Contact us
Join the community
to join the community
Try Guance
Start online and pay only for what you use.
Get startedChoose a Guance plan