Resolving svn conflicts

10 Jul 2013

You might have a dedicated tool or workflow for this, but this is the poor man’s version that should work on all systems without any extra software or previous configuration. You are trying to commit some changes to a file, but instead you are greeted with something like:

$ svn commit -m "updated file.txt"
Sending    file.txt
Transmitting file data .svn: Commit failed (details follow):
svn: Out of date: '/myproject/file.txt'

So you go and try to update, only to get:

$ svn update
Updating '.':
Conflict discovered in 'file.txt'.
Select: (p) postpone, (df) diff-full, (e) edit,
        (mc) mine-conflict, (tc) theirs-conflict,
        (s) show all options:

Answer with p, for postpone, so that you get:

C    file.txt
Updated to revision 2.
Summary of conflicts:
  Text conflicts: 1

This will create four files that look like the following:

file.txt      - all versions merged into one, with conflict markers
file.txt.mine - your version with changes, what you were trying to commit
file.txt.r1   - the version (without changes) you had since your last update
file.txt.r2   - the newest version currently in the repository

You might want to have a look some or all of the files to figure out the cause of the conflict. Probably you want to start with file.txt which contains conflict markers such as:

Top piece of bread
<<<<<<< .mine
Grilled Chicken
>>>>>>> .r2
Creole Mustard
Bottom piece of bread

Have a look at the conflicts and edit this file to make it look exactly as you would like the final version now to be. Depending on your situation, you might even want to completely replace this file with one of the other three versions that you have at hand.

When you are satisfied with the current contents of file.txt, then you are ready to mark the conflict as resolved and commit the new version:

$ svn resolved file.txt
Resolved conflicted state of 'file.txt'

$ svn commit -m "updated file.txt"
Sending    file.txt
Transmitting file data .
Committed revision 3.

More details and further discussion at Resolve Any Conflicts on the SVN book.