jupp0r was on the right track. First, cd
to the root of your repository. Then:
git commit -a -m 'Backup commit.'
git branch pre-patch
git reset --hard HEAD~
git diff --patch -w HEAD pre-patch > patch.diff
git apply patch.diff
I'm not sure whether this will work for binary changes. If not, you can commit those separately beforehand. If this process fails, your code is in the pre-patch
branch.
What this does:
- Creates a commit and a branch to store the full changes. This also serves as a backup.
- Goes back a step, to before those changes were made.
- Gets the "diff -w" from the old code to the new code, formatted as a patch.
- Applies the patch.
Note: If you've already committed the change and want to modify it, just omit the first step.