There is a guide to splitting commits in the rebase manpage. The quick summary is:
-
Perform an interactive rebase including the target commit (e.g.
git rebase -i <commit-to-split>^ branch
) and mark it to be edited. -
When the rebase reaches that commit, use
git reset HEAD^
to reset to before the commit, but keep your work tree intact. -
Incrementally add changes and commit them, making as many commits as desired.
add -p
can be useful to add only some of the changes in a given file. Usecommit -c ORIG_HEAD
if you want to re-use the original commit message for a certain commit. -
If you want to test what you’re committing (good idea!) use
git stash
to hide away the part you haven’t committed (orstash --keep-index
before you even commit it), test, thengit stash pop
to return the rest to the work tree. Keep making commits until you get all modifications committed, i.e. have a clean work tree. -
Run
git rebase --continue
to proceed applying the commits after the now-split commit.