Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

SVN conflict resolution

SVN conflict resolution


Cause of version conflict:

Suppose users A and B both updated the file kingtuns.txt when the version number was 100. User A submitted kingtuns.txt to the server after finishing modifications; the submission succeeded and the version number of kingtuns.txt became 101. Meanwhile, user B modified the kingtuns.txt file at version 100 and, after finishing, submitted to the server. Because the modification was not based on the latest version 101, the submission failed.

We have checked out the runoob01 repository locally; next we will implement a solution for version conflicts.

We found that the HelloWorld.html file has an error and needs to be modified and committed to the repository.

We modified the content of HelloWorld.html to "HelloWorld! https://www.runoob.com/".



root@runoob:~/svn/runoob01/trunk# cat HelloWorld.html 

HelloWorld! http://www.runoob.com/

Use the following command to view the changes:



root@runoob:~/svn/runoob01/trunk# svn diff 

Index: HelloWorld.html

===================================================================

--- HelloWorld.html     (revision 5)

+++ HelloWorld.html     (working copy)

@@ -1,2 +1 @@

-HelloWorld! http://www.runoob.com/

+HelloWorld! http://www.runoob.com/!

Try using the following command to commit his changes:



root@runoob:~/svn/runoob01/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 found that the commit failed.

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

To avoid the two users' code overwriting each other, Subversion does not allow us to perform such an operation. Therefore, we must update the working copy before committing changes. So we use the update command, as follows:



root@runoob:~/svn/runoob01/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)

Enter "mc" here, to take the local file as the primary one. You can also use its options to perform different operations on the conflicting file.

The default is to update 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 changes can be committed safely.



root@runoob:~/svn/runoob01/trunk# svn commit -m "change HelloWorld.html second"

Sending        HelloWorld.html

Transmitting file data .

Committed revision 7.