I've tried editing a php file in TextWrangler with line endings set to Unix, in NetBeans, and in vim. When I save the diff to a patch and then try to apply it, it gives whitespace errors. When I type git diff
I can see ^M
at the ends of my lines, but if I manually remove these in vim, it says my patch file is corrupted, and then the patch doesn't apply at all.
I create a patch with the following command:
git diff > patchname.patch
And I apply it by checking out a clean version of the file to be patched and typing
git apply patchname.patch
How can I create this patch without whitespace errors? I've created patches before and never run into this issue.
git diff
andfit show
, so any patch made with such code will have trailing whitespaces. If you have linux kernel git repository locally (linus kernel tree), you can rungit show 402bae597e
. It will show you a trailing whitespace before static DEVICE_ATTR_RO(flags); and the closing braces in previous line, even though they are not present in the code. – Esotericgit diff
. You can see extra whitespaces before unchanged files. These then get introduced to the patch whengit format-patch
is used – Esoteric