SVN Conflict Resolution
Reasons for Version Conflict:
Suppose users A and B both updated the file kingtuns.txt at version 100. After user A made changes and successfully committed kingtuns.txt to the server, the file's version became 101. Meanwhile, user B made changes to the version 100 of kingtuns.txt and attempted to commit, resulting in a failure because the changes were not made on the latest version 101.
We have checked out the tutorialpro01 repository locally, and now we will implement the method to resolve version conflicts.
We found an error in the HelloWorld.html file and need to modify and commit it to the version repository.
We will change the content of HelloWorld.html to "HelloWorld! https://www.tutorialpro.org/".
root@tutorialpro:~/svn/tutorialpro01/trunk# cat HelloWorld.html
HelloWorld! http://www.tutorialpro.org/
Use the following command to view the changes:
root@tutorialpro:~/svn/tutorialpro01/trunk# svn diff
Index: HelloWorld.html
===================================================================
--- HelloWorld.html (revision 5)
+++ HelloWorld.html (working copy)
@@ -1,2 +1 @@
-HelloWorld! http://www.tutorialpro.org/
+HelloWorld! http://www.tutorialpro.org/!
Attempt to commit the changes using the following command:
root@tutorialpro:~/svn/tutorialpro01/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 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 outdated.
To prevent both users' code from overwriting each other, Subversion does not allow us to perform such operations. Therefore, we must update our working copy before committing changes. So, use the update command as follows:
root@tutorialpro:~/svn/tutorialpro01/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, "mc" was entered to prioritize the local file. You can also use other options to handle the conflicting file differently.
By default, it updates to the latest version, but you can also specify which version to update to:
svn update -r6
At this point, the working copy is synchronized with the repository and it is safe to commit changes:
root@tutorialpro:~/svn/tutorialpro01/trunk# svn commit -m "change HelloWorld.html second"
Sending HelloWorld.html
Transmitting file data .
Committed Revision 7.