How do I get patch to ignore carriage returns?

James McMahon picture James McMahon · Oct 13, 2011 · Viewed 20.6k times · Source

I'm attempting to apply a patch to a file with Windows line endings on a Linux system and I'm getting conflicts due to the carriage returns in the file.

The -l option (ignore whitespace) isn't ignoring the EOL characters. Is there anyway to get patch to ignore windows style line endings?

Answer

Jon picture Jon · Jun 7, 2012

Try using the --binary option, from the manpage (emphasis mine)

--binary

Write all files in binary mode, except for standard output and /dev/tty. When reading, disable the heuristic for transforming CRLF line endings into LF line endings. (On POSIX -conforming systems, reads and writes never transform line endings. On Windows, reads and writes do transform line endings by default, and patches should be generated by diff --binary when line endings are significant.)

I don't fully understand the above, but it worked for me on a Linux machine to apply a Unix patch onto a DOS file.