2011-07-15

Patch files with git diff

In order to create a patch file that is usable with "patch -p0 < patchfile" with "git diff", the option "--no-prefix" has to be used:
git diff --no-prefix > patchfile

Now the patch can be applied using:
patch -p0 < patchfile

If you already have a patch file out of "git diff" where the "--no-prefix" option was not specified, the patch must be applied as follows:
patch -p1 < patchfile

This way the standard prefixes a/ and b/ are ignored.