问题描述
我试图在 Linux 系统上对一个以 Windows 行结尾的文件应用补丁,但由于文件中的回车符,我遇到了冲突.
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.
-l
选项(忽略空格)不会忽略 EOL 字符.有没有办法让补丁忽略windows样式的行尾?
The -l
option (ignore whitespace) isn't ignoring the EOL characters. Is there anyway to get patch to ignore windows style line endings?
推荐答案
尝试使用 --binary 选项,来自联机帮助页(重点是我的)
Try using the --binary option, from the manpage (emphasis mine)
--二进制
以二进制模式写入所有文件,标准输出和/dev/tty 除外.读取时,禁用将 CRLF 行尾转换为 LF 行尾的启发式.(在符合 POSIX 的系统上,读写从不转换行尾.在 Windows 上,默认情况下,读和写会转换行尾, 当行尾很重要时,补丁应该由 diff --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.)
我不完全理解上述内容,但在 Linux 机器上将 Unix 补丁应用于 DOS 文件对我有用.
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.
这篇关于如何获得补丁以忽略回车?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!