Skip to content

Instantly share code, notes, and snippets.

@webcaetano webcaetano/file.md
Created Jun 14, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.