0

In diffutils' manual

diff3 mine older yours

You can remember the order of the arguments by noting that they are in alphabetical order.

You can think of this as subtracting older from yours and adding the result to mine, or as merging into mine the changes that would turn older into yours. This merging is well-defined as long as mine and older match in the neighborhood of each such change. This fails to be true when all three input files differ or when only older differs; we call this a conflict. When all three input files diff er, we call the conflict an overlap.

...

The ‘-e’, ‘-3’ and ‘-x’ options select only unmerged changes, i.e. changes where mine and yours differ; they ignore changes from older to yours where mine and yours are identical, because they assume that such changes have already been merged.

What does "mine and older match in the neighborhood of each such change" mean?

Does "when only older differs" mean that mine and yours are the same but different from older? Isn't merging straightforward in that we can just use either mine or yours? Why isn't merging well-defined in this case?

How do the three cases cover all the possible cases:

  • When "mine and older match in the neighborhood of each such change"

  • "when all three input files differ"

  • "when only older differs"?

Is "changes from older to yours where mine and yours are identical" the same as the changes "when only older differs"?

Thanks.

2 Answers 2

3

What does "mine and older match in the neighborhood of each such change" mean?

“mine and older match in the neighborhood of each such change” means that when considering each change between “older” and “yours”, the context of the change can be found in “mine” too. Put another way, it means that “mine” and “older” are identical as far as each individual change between “older” and “yours” is concerned. Consider

mine            other           yours
------------------------------------------------
Some text       Some text       Some text
Some more text  Some more test  Changed text
Continues       Continues       Continues
Mine changes    This is gone    This is gone
The file ends   The file ends   The file ends

One line has changed between “other” and “mine”, and another has changed between “other” and “yours”. When looking at the change from “other” to “yours”, we find the same context in “mine”, so the change can be applied to “mine” with no ambiguity or conflict.

Does "when only older differs" mean that mine and yours are the same but different from older?

Yes.

Isn't merging straightforward in that we can just use either mine or yours? Why isn't merging well-defined in this case?

The definition of “well-defined” is that the context of the change from “older” to “yours” is identical in “mine”. When “mine” and “yours” are identical, and differ from “older”, then by definition the change isn’t well-defined.

This might seem surprising, but the guiding principle of three-way merges is that any conflict, even if it results in identical content, must be identified and examined by the user. I don’t have an example to hand but it does happen that a given line is identical in “mine” and “yours”, but given other changes which are being merged, isn’t desirable as-is in the merge result.

Another way of considering this, is that the aim of a three-way merge is to reconcile two diverging histories: the history which led from “older” to “mine”, and the history which led from “older” to “yours”. Even if both histories lead to the same content, they need to be re-evaluated and not blindly applied.

The developers of diff3 did realise that such changes should often be applied anyway; the -e, -3, and -x options do this.

How do the three cases cover all the possible cases?

The first case describes a global analysis, but I think the other two should be understood in the context of a single change. If we consider all three cases viewed per change (from “older” to “yours”), they become (remember “older” and “yours” are different):

  • “mine” and “older” are identical
  • “mine“ and “older” are different, and “mine” and “yours” are different
  • “mine“ and “older” are different, and “mine” and “yours” are identical

Consider the truth table:

mine == older    mine == yours    older == yours    Case
--------------------------------------------------------
     Yes              Yes               Yes         N/A
     Yes              Yes               No          Imp.
     Yes              No                Yes         N/A
     Yes              No                No          1
     No               Yes               Yes         N/A
     No               Yes               No          3
     No               No                Yes         N/A
     No               No                No          2

N/A means the case isn’t considered: there is no change from “older” to “yours”. Imp. means the case is impossible (through transitivity of equality). This shows that three cases are sufficient to cover all possibilities.

Is "changes from older to yours where mine and yours are identical" the same as the changes "when only older differs"?

Yes.

10
  • Thanks. Is "unmerged changes, i.e. changes where mine and yours differ" the same as either when "mine and older match in the neighborhood of each such change" or "when all three input files differ"?
    – Tim
    Commented Nov 9, 2018 at 17:31
  • It’s the same as both; see the truth table (lines 4 and 8). Commented Nov 9, 2018 at 17:39
  • Thanks. Regarding the meaning of whether merging is "well-defined": (1) "This merging is well-defined as long as mine and older match in the neighborhood of each such change." In that case, is merging done by choosing yours over mine and older? What does "well-defined" mean? (2) "when only older differs", mine and yours are the same but different from older, so isn't merging straightforward in that we can just choose either mine or yours over older? Why isn't merging well-defined in this case?
    – Tim
    Commented Nov 9, 2018 at 17:51
  • (3) In my guess, merging isn't well defined if and only if mine, older and yous differ from one another, and is well defined if and only if any two of mine, older and yours are the same.
    – Tim
    Commented Nov 9, 2018 at 18:06
  • Thanks for update. (1) "The developers of diff3 did realise that such changes should often be applied anyway; the -e, -3, and -x options do this." Do you mean diff3 with the -e, -3, and -x options will automatically merge changes where yours and old differ and mine and yours are the same? How does it perform merging in such a case?
    – Tim
    Commented Nov 9, 2018 at 18:42
1

It is well defined in each of mine and yours is a change from older, such that they remove text; add text in a different place; or they change text, but don't both change the same text.

That is the computer can not know what is wanted if we both change the same thing (in different ways), or if we add something in the same place, then it does not know in what order to place them.

You must log in to answer this question.

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