Take the 2-minute tour ×

Standard linux patch hard-coded only for unix text files.

PS: I do no want convert ALL to unix and then convert result back.

share|improve this question
Why do you have (apparently a lot of) text files with CRLF line endings on a Unix system? –  Daniel Pryden Jan 17 '10 at 3:24
sources for ARM which previously cross-developed on win32. –  vitaly.v.ch Jan 18 '10 at 13:07
add comment

6 Answers

Will the dos2unix command fix the file?

share|improve this answer
problem may be solved by converting ALL source to unix and after converting back. but it's sucks. –  vitaly.v.ch Jan 16 '10 at 8:51
add comment

Use the --binary option. Here is the relevant snippet from the man page:

      line endings are significant.)
share|improve this answer
add comment

I've run into this problem before a few times. This is what I've discovered:

  • The Linux patch command will not recognize a patchfile that has CRLF in the patch 'meta-lines'.
  • The line-endings of the actual patch content must match the line endings of files being patched.

So this is what I did:

  1. Use dos2unix to convert patch files to LF line-endings only.
  2. Use dos2unix to convert the files being patched to LF line-endings only.
  3. Apply patch.

You can use unix2dos to convert patched files back to CRLF line-endings if you want to maintain that convention.

share|improve this answer
add comment


dos2unix patchfile.diff
dos2unix $(grep 'Index:' patchfile.diff | awk '{print $2}')
patch --verbose -p0 -i patchfile.diff

The last line depends on whether you want to keep the CRLFs or not.


PS. This should've been a reply to cscrimge's post. DS.

share|improve this answer
add comment

perl -i.bak -pe's/\R/\n/g' inputfile to convert any line ending to the standard.

share|improve this answer
Thanks, it's interested but not applicable in my situation. –  vitaly.v.ch Jan 16 '10 at 8:53
It answers the question in the title if the diff is based on lines, as they usually are. –  Anonymous Jan 16 '10 at 9:25
add comment
up vote -3 down vote accepted

It can be solved by hacking patch utility

share|improve this answer
add comment

Your Answer


