开发者

How to read patch .rej files

开发者 https://www.devze.com 2022-12-24 10:38 出处:网络
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.

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.


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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消