- publishing free software manuals
Comparing and Merging Files with GNU diff and patch
by David MacKenzie, Paul Eggert, and Richard Stallman
Paperback (6"x9"), 120 pages
ISBN 0954161750
RRP £12.95 ($19.95)

"Well packaged... the quality of information is excellent" --- Linux User and Developer Magazine (Issue 36, Feb 2004) Get a printed copy>>>

7.3 diff3 Hunks

Groups of lines that differ in two or three of the input files are called diff3 hunks, by analogy with diff hunks (see section 1.1 Hunks). If all three input files differ in a diff3 hunk, the hunk is called a three-way hunk; if just two input files differ, it is a two-way hunk.

As with diff, several solutions are possible. When comparing the files ‘A’, ‘B’, and ‘C’, diff3 normally finds diff3 hunks by merging the two-way hunks output by the two commands ‘diff A B’ and ‘diff A C’. This does not necessarily minimize the size of the output, but exceptions should be rare.

For example, suppose ‘F’ contains the three lines ‘a’, ‘b’, ‘f’, ‘G’ contains the lines ‘g’, ‘b’, ‘g’, and ‘H’ contains the lines ‘a’, ‘b’, ‘h’. ‘diff3 F G H’ might output the following:

====2
1:1c
3:1c
  a
2:1c
  g
====
1:3c
  f
2:3c
  g
3:3c
  h

because it found a two-way hunk containing ‘a’ in the first and third files and ‘g’ in the second file, then the single line ‘b’ common to all three files, then a three-way hunk containing the last line of each file.

ISBN 0954161750Comparing and Merging Files with GNU diff and patchSee the print edition