Non-Conflict Change Example

I am trying to understand the details of subversion merge commands. I think that understanding the difference between change, which is also a conflict, and change, which is not a conflict, would help.

This is a continuation of this topic.

+10
svn
Jan 22
source share
2 answers

A change that is a conflict is when two people make changes to the same file so that these two changes cannot be automatically resolved.

1) Let's start with an example of a non-conflict merger.

Original file

line1 line2 line3 

Person A changes it to this:

 line1CHANGED line2 line3 

Person B changes it to the following:

 line1 line2CHANGED line3 

When both are checked and merged, there is no conflict, because it can easily resolve the creation of this final file:

 line1CHANGED line2CHANGED line3 

Subversion will treat this automatically as a merge.

2) Now an example of conflicting changes.

Original file

 line1 line2 line3 

Person A changes it to this:

 line1CHANGED_BY_A line2 line3 

Person B changes it to the following:

 line1CHANGED_BY_B line2 line3 

It is not possible to combine automatically, so this is a conflict. You will need to decide, either with the help of a person, or change him, or change a person. In this case, subversion warns you of conflicts and requires you to decide how to resolve them.

3) Finally, you can have both conflicting and non-conflict changes within the same revision.

Original file

 line1 line2 line3 

Person A changes it to this:

 line1CHANGED_BY_A line2ALSO_CHANGED_BY_A line3 

Person B changes it to the following:

 line1CHANGED_BY_B line2 line3ALSO_CHANGED_BY_B 

Now, in this example, both people have changed the file, and on line 1 there is a conflicting change that should be allowed, but lines 2 and 3 are non-conflicting changes and can be resolved automatically.

You can solve this problem in several ways.

First, you can completely accept file A or B and refuse another. This will cause other individuals to lose conflicting changes. Let's say you decide to completely allow the use of A, your final file will be:

 line1CHANGED_BY_A line2ALSO_CHANGED_BY_A line3 

(Exactly, the file and all changes to B are discarded)

Secondly, you can only allow conflicting changes and save all non-conflict changes. That you would choose either a change of A or B for the first line, and still get both other line changes from both people. So, say, for example, you decide to resolve conflicts using A, your final file:

 line1CHANGED_BY_A line2ALSO_CHANGED_BY_A line3ALSO_CHANGED_BY_B 

An alternative you can use tools like KDiff , which support viewing each conflict separately (because, of course, you can have mutliple changes, both conflicting and non-conflicting, in the same file), which allows you to choose different resolution methods for each.

If you are having trouble understanding merging with command line tools, I highly recommend that you take a look at KDiff (or some other GUI merge / reverse tool) as they display files next to each other (along with the original) and allow you to visualize what each resolution action will do.

+22
Jan 22 '10 at 23:20
source share

Consider such a function (call it revision 1)

 void foo(){ int bar; } 

Now suppose that two people make changes to this feature, starting with version 1.

Alice:

 void foo(){ char bar; } 

Bean:

 double foo(){ double bar; bar = 0; return bar; } 

For this example, suppose Alice makes her changes.

Now Bob goes to commit the changes, and svn tells Bob that he is out of date, and he needs to update and merge the changes. So Bob starts the update, and the merge happens.

Basically, it's (somewhat) easy to see what is happening, it's an analysis that decides what Bob changed from version 1 and what Alice changed from revision 1. A simple merge will lead to something like

 double foo(){ [conflict] bar; bar = 0; return bar; } 

Note that both Alice and Bob changed the type of bar to int , except that Alice made it char and Bob made it double . Merging cannot decide which one is correct (it does not perform code analysis), since human Bob should help resolve the conflict.

The example, of course, is somewhat contrived, and, with the exception of the noted conflict, all other changes are not conflicts.

If Bob did not change the type of bar , the files would merge without conflict.

+6
Jan 22 '10 at 23:10
source share



All Articles