如何在linux中使用在Windows(使用CRLF)中创建的补丁?我

vit*_*.ch 10 diff patch

标准linux补丁仅针对unix文本文件进行硬编码.

PS:我不想将ALL转换为unix,然后将结果转换回来.

csc*_*mge 14

我几次遇到这个问题.这是我发现的:

  • Linux patch命令无法识别补丁'meta-lines'中包含CRLF的补丁文件.
  • 实际修补程序内容的行尾必须与要修补的文件的行结尾匹配.

所以这就是我做的:

  1. 使用dos2unix仅将补丁文件转换为LF行尾.
  2. 使用dos2unix仅将正在修补的文件转换为LF行结尾.
  3. 应用补丁.

如果要维护该约定,可以使用unix2dos将修补文件转换回CRLF行结尾.


小智 14

使用--binary选项.以下是手册页中的相关代码段:

  --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.  This option  is  needed
      on  POSIX systems when applying patches generated on non-POSIX systems to non-POSIX files.  (On
      POSIX systems, file 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.)
Run Code Online (Sandbox Code Playgroud)


小智 8

联合:

dos2unix patchfile.diff
dos2unix $(grep 'Index:' patchfile.diff | awk '{print $2}')
patch --verbose -p0 -i patchfile.diff
unix2dos $(grep 'Index:' patchfile.diff | awk '{print $2}')
Run Code Online (Sandbox Code Playgroud)

最后一行取决于您是否要保留CRLF.

M.

PS.这应该是对cscrimge帖子的回复.DS.

  • 对我来说有用的是上面的内容,但是为了'+++'而不是'Index:'. (2认同)

Ano*_*ous 0

perl -i.bak -pe's/\R/\n/g' inputfile将任何行结尾转换为标准。