Please use a browser that supports javascript

Bogeskov.dk

Git Splitting Unpublished commit

Repeat after me: I DID NOT PUSH MY CHANGES

Given you have a git log that looks like this:

git log --pretty=oneline
6e6fa6d8e1fdd11cbc56adfc55c20da5be413d4c cleanup
6fbf2152172443983f365227cde5118d9362bb25 big
2fae91d179ca5ad96638962b01c205de1fcfa542 includes
408bd2a08c818fcf5885d4e96e7b3d06271c4179 sleep
0fced76817e200d6c87db41677cd41c92d686240 Initial

but "big" is actually 2 commits you can do this:

rebase the commit:

git rebase -i 6fbf2152172443983f365227cde5118d9362bb25^

and change "pick 6fbf215 big" to "edit 6fbf215 big" then save. This stops you in time after the content of the 6fbf215 commit has been applied, but before it has been committed.

To get the content of the commit compared to previous commit:

git reset 6fbf2152172443983f365227cde5118d9362bb25^

now you can look around with git status, git diff and so on. then you add the parts you want in the first part of the change:

git add --patch my-file.cc

which allows you to add diff blocks interactively. Now you have the first part or your commit added and can commit it (remember to add new files too)

git commit -m "Part 1"

To create part 2, you commit everything (after again adding new files)

git commit -a -m "Part 2"

Just add the remaining commits on top:

git rebase --continue

and you should have the following git log:

git log --pretty=oneline
70ea3693bb600adbb4238cd574e5278613558668 cleanup
504ccf89166d6f0a23c211e57fba50213df68cb5 Part 2
c9df3d7a13e9aaf8d5f45b7323bb53053ad63e7b Part 1
2fae91d179ca5ad96638962b01c205de1fcfa542 includes
408bd2a08c818fcf5885d4e96e7b3d06271c4179 sleep
0fced76817e200d6c87db41677cd41c92d686240 Initial

And the commit "big" has been split up into "Part 1" and "Part 2"

Repeat after me: I DID NOT PUSH MY CHANGES

because as you can se from the commit named "clean" it has changed hash, which means: If you pushed it, and somebody pulled if, you will break their clone. People have had their push privileges revoked for this behavior.