Conflict Resolution

This page will take you through the process of dealing with a conflict when it occurs.

A conflict can occur when two people modify the same file and then try and commit the changes. Consider a simple project containing just one file called "Simple.java":

class Simple {
 // This is a simple class!
 public void doSomething() {
  // This is a simple method!
 }
}

Suppose Alice and Bob are working on this file. At the start, they both have identical copies. Then, Alice makes a small change to he copy of the file and it now looks like:
class Simple {
 // This is a simple class!
 public void doSomething() {
  // This is a simple method!
  System.out.println("doSomething was called");
 }
}
Bob, of course, still has the original copy. Suppose that he now makes a small change of his own, so that his copy looks like:
class Simple {
 // This is a simple class!
 public void doSomething() {
  // This is a simple method!
 }
 public void anotherMethod() {
  // This is another method
 }
}

Since Alice has not yet committed her change to the repository, Bob's version will not contain her print method. Now she commits her change to the repository. When Bob attempts to commit his change, a conflict will occur. If Bob had used the "Team->Commit" menu option, he would see the following:

example12.jpg

The best way for Bob to proceed from this point is to try again using the "Synchronise with Repository" option on the Team menu. If he had done this anyway, then he could proceed from here. Eclipse will show a little red diamond next to the "Simple.java" file. Double-clicking on the file will open the comparison view, which looks like the following:

example13.jpg

Here you can see the little red diamond next to the "Simple.java" file. This indicates there is a conflict that must be resolved. In the source compare window, Eclipse shows us the contents of the local file and the remote file. The differences between them are shown in boxes, with lines indicating where they should go. In this case, the conflict is easy to resolve. We just want to copy Alice's change into Bob's file and commit that. Eclipse provides a convenient way of doing this, via the "Copy Non-Conflicting Changes" buttons:

example14.jpg

Bob presses the "Copy Non-Conflicting Changes from Right to Left" button, which copies Alice's print method into his local file. Then, he right-clicks on the "Simple.java" file and selects "Mark as merged". This tells Eclipse that Bob has merged his changes with those of Alice. Finally, Bob selects "Commit" and proceeds as usual with committing his changes.

Introduction | Creating a Repository | Subversion Basics | Dealing with Conflict.