Splitting Commits

Splitting a Commit During Interactive Rebase

"wip" mixes code and documentation. While the rebase is stopped on it, undo the commit but keep its changes in the working tree with a mixed reset, then commit the two parts separately and let the rebase finish:

Splitting the stopped commit in twoShell
git reset -q HEAD~
git status --short
git commit -qm "Add ?offset= to /api/books" app.js
git commit -qam "Document ?limit= and ?offset= in the README"
git rebase --continue
git log --oneline -4
Output
 M README.md
 M app.js
Successfully rebased and updated refs/heads/paginate-api.
53cf24b Document ?limit= and ?offset= in the README
9f72ca8 Add ?offset= to /api/books
237ad84 Add ?limit= to /api/books
e78d7c2 Pin Node.js 24 with .nvmrc

git commit <path> commits only that file. When one file holds both parts, stage hunks with git add -p (Staging Changes with git add) instead. Three clean commits replaced three messy ones, and the typo never happened.