Skip to content

Instantly share code, notes, and snippets.

@webcaetano
Created June 14, 2017 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webcaetano/718f160983eb9f6e383e002989d46fda to your computer and use it in GitHub Desktop.
Save webcaetano/718f160983eb9f6e383e002989d46fda to your computer and use it in GitHub Desktop.
Split commit in multiple

git rebase -i will do it.

To split apart your most recent commit, first:

$ git reset HEAD~ Now commit the pieces individually in the usual way, producing as many commits as you need.

If it was farther back in the tree, then

$ git rebase -i HEAD~3 where 3 is how many commits back it is.

If it was farther back in the tree than you want to count, then

$ git rebase -i 123abcd^ where 123abcd is the SHA1 of the commit you want to split up.

When you get the rebase edit screen, find the commit you want to break apart. At the beginning of that line, replace pick with edit (e for short). Save the buffer and exit. Rebase will now stop just after the commit you want to edit. Then:

$ git reset HEAD~ Commit the pieces individually in the usual way, producing as many commits as you need, then

$ git rebase --continue

Source : https://stackoverflow.com/a/6217314/2081518

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment