如何获得补丁以忽略回车符?

发布于 2024-12-09 19:16:49 字数 150 浏览 1 评论 0原文

我正在尝试对 Linux 系统上具有 Windows 行结尾的文件应用补丁,但由于文件中的回车符而出现冲突。

-l 选项(忽略空格)不会忽略 EOL 字符。 是否有补丁可以忽略 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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

尛丟丟 2024-12-16 19:16:49

尝试使用联机帮助页中的 --binary 选项(强调我的)

--二进制

以二进制模式写入所有文件,标准输出和/dev/tty 除外。 读取时,禁用将 CRLF 行结尾转换为 LF 行结尾的启发式。(在 POSIX 兼容系统上,读取和写入从不转换行结尾。在 Windows 上,读取和写入默认情况下会转换行结尾,当行结尾很重要时,应该通过 diff --binary 生成补丁。)

我不完全理解上面的内容,但它对我在 Linux 机器上将 Unix 补丁应用到 DOS 文件有效。

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.

又爬满兰若 2024-12-16 19:16:49

这是一个链接 http://www.chemie.fu-berlin.de/chemnet /use/info/diff/diff_2.html

-w' 和--ignore-all-space' 选项会忽略差异,即使一个文件有空格且另一个文件没有空格也是如此。空白字符包括制表符、换行符、垂直制表符、>换页符、回车符和空格

运行 diff,如:diff -w file1.txt file2.txt

Here's a link http://www.chemie.fu-berlin.de/chemnet/use/info/diff/diff_2.html

The -w' and--ignore-all-space' options ignore difference even if one file has white space >where the other file has none. White space characters include tab, newline, vertical tab, >form feed, carriage return, and space

Run diff like: diff -w file1.txt file2.txt

与他有关 2024-12-16 19:16:49

我使用以下命令将所有感兴趣的文件转换为 unix 行结尾来解决此问题。

dos2unix `grep Index\: mixed-line-ending.patch | sed -e 's/Index\://'`
dos2unix mixed-line-ending.patch
patch -p0 < mixed-line-ending.patch

I work around this using the following commands to convert all files of interest to unix line endings.

dos2unix `grep Index\: mixed-line-ending.patch | sed -e 's/Index\://'`
dos2unix mixed-line-ending.patch
patch -p0 < mixed-line-ending.patch
蓝咒 2024-12-16 19:16:49

我遇到了一个 diff 问题,该 diff 是从 git diff 控制台输出手动复制并粘贴到带有 LF 的补丁文件中的。为了让该补丁文件再次工作 - 能够应用于使用 CR 和 LF 的实际文件 - 必须手动完成几件事:

  • 找到“^M”的所有实例并删除它们,
  • 将 CR 添加到所有行在帅哥中 - 但不是
  • 帅哥中所有空行上的元格式行(@@等),在第一列中添加缺少的空格

joe语法突出显示在那里非常有用,因为它着色了我一修好就好好帅哥 他们。

I had this problem with a diff that was manually copied and pasted from git diff console output, into a patch file with LFs. To get that patch file to work again - to be able to be applied on the actual files that were using CRs and LFs - several things had to be done manually:

  • find all instances of "^M" and drop them
  • add CR to all lines within the hunks - but not the meta format lines (@@ etc)
  • on all lines within hunks that were empty, add the missing space in the first column

joe syntax highlighting was very helpful there, because it colored hunks properly as soon as I fixed them.

油焖大侠 2024-12-16 19:16:49

告诉patch忽略空格:

     -l, --ignore-whitespace
             Causes the pattern matching to be done loosely, in case the tabs
             and spaces have been munged in your input file.  Any sequence of
             whitespace in the pattern line will match any sequence in the
             input file.  Normal characters must still match exactly.  Each
             line of the context must still match a line in the input file.

这也会忽略EOL的不匹配——至少在FreeBSD上,使用patch版本2.0-12u11。

Tell patch to ignore white space:

     -l, --ignore-whitespace
             Causes the pattern matching to be done loosely, in case the tabs
             and spaces have been munged in your input file.  Any sequence of
             whitespace in the pattern line will match any sequence in the
             input file.  Normal characters must still match exactly.  Each
             line of the context must still match a line in the input file.

This ignores mismatches of EOLs too -- at least, on FreeBSD, using patch version 2.0-12u11.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文