Comparing Files
Three-Way

Three-Way Text Comparison

Three-way comparison is the automated difference analysis between two modified files relative to a common reference file, sometimes referred to as a common ancestor. Three-way comparison often involves the use of a revision control system hosting the reference as well as one of the modified files. The analysis involves computing the changes between the two modified files and the reference file and a building a relationship model to facilitate the visualization and enable the merging of the two files into what would become a new revision of the reference file.

The need for a three-way file comparison is frequently present in collaborative projects. For instance, a contributor has made modifications to a local copy of a file that's under source control. In the window of time that the contributor worked on the file, another contributor changes the same file and commits them to the repository. At the moment the first contributor decides to commit her changes, the SCM lets her know that the file has been modified in the meantime and that she needs to consolidate the two sets of changes. These are the kind of scenarios where a three-way comparison is most helpful.

A three-way comparison offers more than two standalone two-way comparisons between each of the modified files and the common reference: it reflects the level of convergence between the two derivative works and their reference. A conflicting change is a case in point—it exists only in the context of a three-way comparison, when a block of text has been modified differently in both derivative works.

Opening a three-way comparison

  • Open a new two-way file comparison and change the comparison window layout to a 3-way comparison layout. The editor for the reference file would move from left to middle, the first modified file would go to its left and the second to its right.
  • If there is an open three-way folder comparison, a double-click on a triplet of files will open these files in a three-way file comparison.
  • If there is one or more history items that were recorded for files participating in three-way comparisons, hold down the Cmd key and select any of these history items.

A simple three-way text file comparison containing one of each possible relationships—deletions, additions, changes, conflicts and pseudo conflicts—is shown on the following screenshot:

Three-way comparison image

Putting the comparison to work

The experience with two-way comparison in browsing differences, editing the files being compared and merging them with standard commands, easily carries over to three-way comparison. Though three-way comparison introduces a new participant in the analysis—the ancestor file—it's usually sufficient to base editing and merging decisions on examination of the differences in two out of the three files at the time.

Differences in agreement

In a well-planned collaborative software development, more frequently than not, two works sharing a common origin have most of their differences with respect to that origin in separate, unrelated blocks of text.

Frequent artifacts of such scenarios are additions and deletions, relative to the ancestor, present only in one of the files, while the respective blocks from the other file remain unchanged. In these cases, apply your skills from working with two-way comparisons to either accept the modifications in the ancestor or to reject them.

It is not uncommon for the authors of the derivative works to make the same change in their locally modified versions. Since the changes are in agreement, two-way comparison and editing techniques are, again, directly applicable as well.

Conflicting differences

DeltaWalker accurately detects different modifications to the same blocks of original text and brings them to your attention for analysis and resolution. These differences require a manual resolution; by default, the areas containing them are outlined in red. To keep your work flowing even in these infrequent cases, DeltaWalker features state-of-the-art text editors, providing you with ample editing power and merging flexibility.

See Also