如何读取补丁.rej文件

发布于 2024-08-25 19:38:56 字数 222 浏览 7 评论 0原文

我在将补丁应用到源代码树时遇到问题,这不是常见的 -p 剥离问题。 patch 能够找到要修补的文件。

具体来说,我的问题是如何读取/解释 patch 在一些大块头失败时创建的 .rej 文件。我见过的大多数关于 patch/diff 的讨论都不包括这一点。

I'm having trouble applying a patch to my source tree, and it's not the usual -p stripping problem. patch is able to find the file to patch.

Specifically, my question is how to read / interpret the .rej files patch creates when it fails on a few hunks. Most discussions of patch/diff I have seen don't include this.

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

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

发布评论

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

评论(3

自演自醉 2024-09-01 19:38:56

一个简单的例子:

$ echo -e "line 1\nline 2\nline 3" > a
$ sed -e 's/2/b/' <a >b
$ sed -e 's/2/c/' <a >c
$ diff a b > ab.diff
$ patch c < ab.diff
$ cat c.rej
***************
*** 2
- line 2
--- 2 -----
+ line b

如您所见:旧文件包含第 2 行,新文件应该包含第 b 行。但是,它实际上包含 c 行(在拒绝文件中不可见)。

事实上,解决此类问题最简单的方法是从 .diff/.patch 文件中取出 diff 片段,将其插入到要修补的文件中的适当位置,然后手动比较代码以找出哪些行实际上引发了冲突。

或者 - 或者:获取原始文件(未修改),对其进行修补并对文件运行三向合并。

A simple example:

$ echo -e "line 1\nline 2\nline 3" > a
$ sed -e 's/2/b/' <a >b
$ sed -e 's/2/c/' <a >c
$ diff a b > ab.diff
$ patch c < ab.diff
$ cat c.rej
***************
*** 2
- line 2
--- 2 -----
+ line b

As you can see: The old file contains line 2 and the new file should contain line b. However, it actually contains line c (that's not visible in the reject file).

In fact, the easiest way to resolve such problems is to take the diff fragment from the .diff/.patch file, insert it at the appropriate place in the file to be patched and then compare the code by hand to figure out, what lines actually cause the conflict.

Or - alternatively: Get the original file (unmodified), patch it and run a three way merge on the file.

尽揽少女心 2024-09-01 19:38:56

Wiggle 是一个在补丁不成功时应用 .rej 文件的好工具。

Wiggle is a great tool for applying .rej files when patch does not succeed.

傲性难收 2024-09-01 19:38:56

我不是处理补丁文件的专家,但我想根据我对补丁文件所包含信息的理解,澄清如何阅读它们。

您的 .rej 文件将告诉您:

  • 原始文件和 .rej 文件之间的区别;
  • 问题代码在原始文件中从哪里开始,有多少行
    在该文件中;
  • 以及代码在新文件中的起始位置,以及该文件中的行数。

因此,给出这条消息,在我的 .rej 文件的开头注明:

diff a/www/js/app.js b/www/js/app.js (被拒绝的帅哥)
@@ -4,12 +4,24 @@

我发现对于我的问题文件 (www/js/app),原始文件(记为 a /www/js/app.js 在第一行)和 .rej 文件(标记为 b/www/js/)从原始文件的第 4 行开始,然后继续12 行(第二行 @@ -4,12, +4,24 @@ 中逗号之前的部分),从新版本文件的第 4 行开始,然后继续24行(@@ -4,12, +4,24 @@中逗号后面的部分。

有关更多信息,请参阅补丁文件的优秀概述(包含我上面注释的信息,如以及有关添加的行和/或文件版本之间的详细信息)位于 http://blog.humphd.org/ 。

当然,欢迎任何更正或澄清

I'm not an expert on dealing with patch files, but I'd like to add some clarity on how to read them based on my understanding of the information they contain.

Your .rej files will tell you:

  • the difference between the original and the .rej file;
  • where the problem code starts in the original file, how many lines it goes on
    for in that file;
  • and where the code starts in the new file, and how many lines it goes on for in that file.

So given this message, noted in the beginning of my .rej file:

diff a/www/js/app.js b/www/js/app.js (rejected hunks)
@@ -4,12 +4,24 @@

I see that for my problem file (www/js/app), the difference between the original (noted as a/www/js/app.js on the first line) and the .rej file (noted as b/www/js/) starts on line 4 of the original and goes on for 12 lines (the part before the comma in @@ -4,12, +4,24 @@ on line two), and starts on line 4 of the new version of the file and goes on for 24 lines (the part after the comma in @@ -4,12, +4,24 @@.

For further information, see the excellent overview of patch files (containing the information I note above, as well as details on lines added and/or between file versions) at http://blog.humphd.org/vocamus-906/.

Any corrections or clarifications welcome of course.

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