This example merges two files that have a common ancestor. The files are file_1 and file_2, and the ancestor file is named matriarch. The descendant files file_1 and file_2 were derived from matriarch by editing. The edits show all varieties of changes that could occur in the descendants: deleting lines, adding new lines, and changing lines.
The content of each line in the example helps to identify whether or not it was changed, and how. The ancestor file contains only twelve lines and is shown in Example 14-1.
Merging does not number lines in the files it loads; the numbers are part of the example text and were placed there for clarity.
1 This line is deleted in file_1 2 This line is in all three files 3 This line is deleted in file_2 4 This line is in all three files 5 This line is in all three files 6 This line is changed in descendants 7 This line is in all three files 8 This line is changed in descendants 9 This line is in all three files 10 This line is changed in file_2 11 This line is in all three files 12 This line is in all three files
Example 14-2 shows the contents of file_1. This file is identical to matriarch with the following exceptions:
The line numbered 1 in the matriarch file was deleted in file_1.
A new line was added following the line numbered 4.
The line numbered 6 was changed (a different change was made to this line in file_2).
The line numbered 8 in the matriarch file was changed (an identical change was made to this line in file_2.)
2 This line is in all three files 3 This line is deleted in file_2 4 This line is in all three files &&& Added to file_1 &&& 6 This line is modified in file_1 from matriarch 5 This line is in all three files 7 This line is in all three files 8 #&# Changed in file_1 and file_2 #&# 9 This line is in all three files 10 This line is changed in file_2 11 This line is in all three files 12 This line is in all three files
Example 14-3 shows the contents of file_2. This file is identical to matriarch with the following exceptions:
The line numbered 3 in the matriarch file was deleted.
The line numbered 6 was changed (a different change was made to this line in file_1).
The line numbered 8 was changed (an identical change was made to this line in file_1).
The line numbered 10 was changed (no change was made to this line in file_1).
A new line was added following the line numbered 11.
1 This line is deleted in file_1 2 This line is in all three files 4 This line is in all three files 5 This line is in all three files 6 This line is altered in file_2 from matriarch 7 This line is in all three files 8 #&# Changed in file_1 and file_2 #&# 9 This line is in all three files 10 ### Changed in file_2 ### 11 This line is in all three files ### Added to file_2 ### 12 This line is in all three files
In the upper left of the Merging window, Merging has reported finding seven differences, of which only one remains unresolved (see Figure 14-1)--six differences were resolved by automerging, and are marked by glyphs in outline font (see Figure 14-2 and Figure 14-3).
The meaning of the glyphs is as follows: a vertical bar means a change in the marked line, a plus sign signifies a line added, a minus sign means a line was deleted. Unresolved states are marked by solid glyphs, unresolved by outline. These glyphs are highlighted in color except when the color map is full. The default significance is: red indicates a change, green indicates a deletion, yellow shows an addition.
The unresolved difference (line 6) is marked by a vertical bar.
Merging highlights the unresolved difference, which it identifies as the line numbered 6 in file_1 and file_2. When differences are being resolved with Merging, the resulting Merging window (filemerge.out) shows the current state of the file with automatic merging.
You could proceed to the next difference by clicking the down arrow above the appropriate file or choosing Navigate > Next. The next difference becomes the current difference.
You could proceed through the differences by clicking on the down arrow.
Automerging preserves a change that was made to one file if no change was made in the other file.
When a difference has not been resolved by automerging, as indicated by the solid highlighted glyph next to the lines involved in the difference, you need to resolve the difference by making a choice. The vertical line indicates that the line has been changed (as opposed to added or deleted). In this case, automerging failed because the same line was changed differently in the two files, and Merging could not decide which change was more valid.
You could resolve this difference in one of the following ways:
Clicking the Accept or Accept & Next button on the left to place the line from file_1 into the output file
Clicking the Accept or Accept & Next button on the right to place the line from file_2 into the output file
Editing the output file by hand
To edit the output file, you would move the pointer into the output file's text pane and place it in the line you want to change. In this example, the following line was typed in:
>>> This line edited by hand <<<
You would choose Edit > Mark Selected as Resolved. This menu item marks the difference as resolved. In this example there are no more unresolved differences, so the next difference remains the current one.
The message in the upper left part of the window now indicates that all differences have been resolved. Nevertheless, you would proceed to verify the automerged differences.
You could continue to navigate through the differences by clicking the down arrow.
The final difference results from a line that was added only to file_2. Merging would place the new line in the output file just as it did when a new line was added to file_1, which resulted in the third difference.
Once all differences have been resolved and the automerged differences verified, you would save the output file. The output file takes the name shown in the Open Files dialog box, which by default is filemerge.out.To write the file, you would choose File > Save or click the Save button. To save the file under another name, you would choose File > Save As.