SVN Resolving Conflicts


Reason for version conflict:

Suppose that both user A and user B updated the file kingtuns.txt when its version number was 100. After user A modified and committed kingtuns.txt to the server, the commit succeeded, and the version number of kingtuns.txt became 101. Meanwhile, user B modified kingtuns.txt based on version 100. When user B committed the modification to the server, the commit failed because the modification was not based on the current latest version 101.

We have already checked out the example01 repository locally. Below we will implement the method to resolve version conflicts.

We find that there is an error in the HelloWorld.html file, and we need to modify the file and commit it to the repository.

We modify the content of HelloWorld.html to "HelloWorld! https://www.example.com/".

root@example:~/svn/example01/trunk# cat HelloWorld.html 
HelloWorld! http://www.example.com/

Use the following command to view the changes:

root@example:~/svn/example01/trunk# svn diff 
Index: HelloWorld.html
===================================================================
--- HelloWorld.html     (revision 5)
+++ HelloWorld.html     (working copy)
@@ -1,2 +1 @@
-HelloWorld! http://www.example.com/
+HelloWorld! http://www.example.com/!

Try to commit his changes using the following command:

root@example:~/svn/example01/trunk# svn commit -m "change HelloWorld.html first"
Sending        HelloWorld.html
Transmitting file data .svn: E160028: Commit failed (details follow):
svn: E160028: File '/trunk/HelloWorld.html' is out of date

At this point, I find that the commit failed.

Because at this time, HelloWorld.html has already been modified by user02 and committed to the repository. Subversion will not allow user01 (the svn account used in this example) to commit the changes, because user02 has already modified the repository, so our working copy is out of date.

In order to prevent the two people's code from overwriting each other, Subversion does not allow us to perform such an operation. Therefore, before committing changes, we must first update the working copy. So use the update command as follows:

root@example:~/svn/example01/trunk# svn update
Updating '.':
C    HelloWorld.html
Updated to revision 6.
Conflict discovered in file 'HelloWorld.html'.
Select: (p) postpone, (df) show diff, (e) edit file, (m) merge,
        (mc) my side of conflict, (tc) their side of conflict,
        (s) show all options: mc
Resolved conflicted state of 'HelloWorld.html'
Summary of conflicts:
  Text conflicts: 0 remaining (and 1 already resolved)

Here enter "mc" to give priority to the local file. You can also use other options to perform different operations on the conflicting files.

By default, it updates to the latest version. We can also specify which version to update to.

svn update -r6

At this point, the working copy is synchronized with the repository, and the changes can be safely committed.

root@example:~/svn/example01/trunk# svn commit -m "change HelloWorld.html second"
Sending        HelloWorld.html
Transmitting file data .
Committed revision 7.
Other Extensions