Reputation: 415
I'm trying to create a patch using diff, but I can't get the patch to use the line end characters used in the files when creating a new file or to change the line ending when the file changes it. Basically, I'm doing:
cp -r dir1 dir3
diff -ruN dir1 dir2 > dir3\patch.txt
cd dir3
patch -p1 < patch.txt
All the changes between dir1
and dir2
properly apply, except the end of line character for new files is defaulting to CR+LF
, even where the file in dir2
uses LF
as an end of line marker. Also, any files where the difference between them is just a line end change are not patched in any way -- diff doesn't seem to see any change.
So running diff -rq dir2 dir3
gives a bunch of Files aaa and bbb differ
, but diff -rwq dir2 dir3
works fine.
I'm using diff - GNU diffutils version 2.7
and patch 2.5
from UnxUtils
on Windows XP.
Is there any way to make new and changed files included in the patch keep the line ending from the original file?
Upvotes: 1
Views: 2147
Reputation: 415
This works:
cp -r dir1 dir3
diff --binary -ruN dir1 dir2 > dir3\patch.txt
cd dir3
patch --no-backup-if-mismatch --binary -u -p1 < patch.txt
Not using the --binary
flag means that the file is parsed line by line, ignoring EOL. For some reason, it won't always patch cleanly (gives a Hunk #1 succeeded at 1 with fuzz 1.
message) so I had to include --no-backup-if-mismatch
to prevent it making .orig
files. The -u
seems to be optional, since patch will figure the patch type out on it's own.
Upvotes: 1