2

diffutils' manual says, in diff3 -A mine older yours

The ‘--show-all’ (‘-A’) option acts like the ‘-e’ option, except that it brackets conflicts, and it outputs all changes from older to yours, not just the unmerged changes.

I have three files, each with four lines of numbers

$ paste f1 f2 f3
0   0   1
2   1   2
2   3   3
4   5   6

Is it correct that there is no merged changes, so -A and -e should both output the unmerged changes only?

How shall I understand the following different outputs by -A and by -e? I guess that I lack some knowledge to understand the ed script generated by -A. For example, I am not sure what this command does at the end of the output by -A. Usually a command is followed by lines to be added, but there doesn't seem to be any line following the command:

0a
<<<<<<< f1
.

Thanks.


Among the changes from f2 to f3, the unmerged changes are

$ diff3 -e f1 f2 f3
1,4c
1
2
3
6
.

All the changes from f2 to f3, consisting of both unmerged and merged changes, are:

$ diff3 -A f1 f2 f3
4a
||||||| f2
0
1
3
5
=======
1
2
3
6
>>>>>>> f3
.
0a
<<<<<<< f1
.
0

1 Answer 1

3

If you apply the ed script that diff3 -A produces to your original file, you will see what it actually does:

$ diff3 -A f[123] >script.ed

(I'm using patch here, but you could also have used ed, but then you would have had to add a command to the end of the script to either write the buffer back to file (w) or print it out on the terminal (%p))

$ patch f1 script.ed
Hmm...  Looks like an ed script to me...
Patching file f1 using Plan A...
done
$ cat f1
<<<<<<< f1
0
2
2
4
||||||| f2
0
1
3
5
=======
1
2
3
6
>>>>>>> f3

This shows that the edits to this bit of the file (which happens to be the whole file in this particular example) is a conflict (it is "bracketed" between <<<<<<< and >>>>>>>). It shows you what the conflict is by giving you the contents of f1 ("my file") followed by the contents in f2 and f3 ("old file" and "your file" respectively).

The difference between this and what diff3 -e produces is that the ed script produced by diff3 -e will transform f1 into f3, ignoring possible conflicts in f2:

$ diff3 -e f[123] >script.ed
$ patch f1 script.ed
Hmm...  Looks like an ed script to me...
Patching file f1 using Plan A...
done
$ cat f1
1
2
3
6

So when the manual says that "it brackets conflicts", it means that it will insert these conflict markers into the resulting file if you apply the diff as a patch.


When it comes to reading the diff, it's a bit difficult if you don't know ed.

4a
||||||| f2
0
1
3
5
=======
1
2
3
6
>>>>>>> f3
.
0a
<<<<<<< f1
.

The last part, which you commented on,

0a
<<<<<<< f1
.

inserts the literal line <<<<<<< f1 at the top of the file which is being edited. This way the diff itself does not have to contain the original contents of f1 (the file being patched).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .