How to read patch .rej files

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.

Leave a Comment