Resolve Conflicts (Merging Others' Changes)

We've already seen how svn status -u can predict conflicts. Suppose you run svn update and some interesting things occur:

$ svn update
U  INSTALL
G  README
Conflict discovered in 'bar.c.
Select: (p)ostpone, (d)iff, (e)dit, (h)elp for more options :

The U and G codes are no cause for concern; those files cleanly absorbed changes from the repository. The files marked with U contained no local changes but were Updated with changes from the repository. The G stands for merGed, which means that the file had local changes to begin with, but the changes coming from the repository didn't overlap with the local changes.

But the next line is part of a feature new in Subversion 1.5 called interactive conflict resolution. This means that the changes from the server overlapped with your own, and you have the opportunity to resolve this conflict. The most commonly used options are displayed, but you can see all of the options by typing h:

...
  (p)ostpone - mark the conflict to be resolved later
  (d)iff     - show all changes made to merged file
  (e)dit     - change merged file in an editor
  (r)esolved - accept merged version of file
  (m)ine     - accept my version of file
  (t)heirs   - accept their version of file
  (l)aunch   - use third-party tool to resolve conflict
  (h)elp     - show this list

Let's briefly review each of these options before we go into detail on what each option means.

(p)ostpone

Leaves the file in a conflicted state for you to resolve after your update is complete.

(d)iff

Display the differences between the base revision and the conflicted file itself in unified diff format.

(e)dit

Open the file in conflict with your favorite editor, as set in the environment variable EDITOR.

(r)esolved

After editing a file, choosing this command tells svn that you've resolved the conflicts in the file and that it should accept the current contents—basically that you've “resolved” the conflict.

(m)ine

Discard the newly received changes from the server and use only your local changes for the file under review.

(t)heirs

Discard your local changes to the file under review and use only the newly received changes from the server.

(l)aunch

Launch an external program to perform the conflict resolution. This requires a bit of preparation beforehand.

(h)elp

Shows the list of all possible commands you can use in interactive conflict resolution.

We'll cover these commands in more detail now, grouping them together by related functionality.