Thursday 16 June 2016

Resolve svn conflicts

SVN contains three different type of conflicts: Text Conflicts, Tree Conflicts and Property Conflicts.

Text Conflicts

Text conflicts happen when local changes have been made to a file and remote revisions also include changes to the file in such a way that it can not be automatically determined how they should be merged.
Sublime SVN includes a quick panel interface that allows for reviewing the different versions of the file, and then resolving the conflict by selecting one of the existing version, or editing the file. The options presented to the user include:
  • Review Old Repository Version
  • Review My Version
  • Review New Repository Version
  • Review/Edit Merged Version
  • Resolve with My Version
  • Resolve with New Repository Version
  • Resolve with Merged Version

Tree Conflicts

Tree conflicts happen when the working copy and remote revisions both perform actions on a file or folder such that it can not be automatically determined which action should be preferred.
This includes situations including:
  • Local delete, incoming edit upon update
  • Local edit, incoming delete upon update
  • Local delete, incoming delete upon update
  • Local missing, incoming edit upon merge
  • Local edit, incoming delete upon merge
  • Local delete, incoming delete upon merge
  • Folder added in both trunk and branch
The only way to resolve a tree conflict via SVN is to accept the current state of the working copy. Thus, if the local version of a file or folder is not the preferred one, the Revert command should be run on it.
Resolution of a tree conflict involving a folder added to both the trunk and a branch separately is slightly different. If the folder added to the branch is preferred, the working copy should be reverted to undo the merge, the folder should be deleted from trunk and then the merge should be re-run.

Property Conflicts

Property conflicts happen when local changes have been made to one or more propeties and remote revisions also include changes to those properties.
The only way to resolve a property conflict is to edit the property to the desired final value and mark it as resolved. Sublime SVN provides a quick panel interface for these operations that allow you to see the conflict, edit the properties and then mark them as resolved.
Example :
Tom decides to add a README file for their project. So he creates the READMEfile and adds TODO list into that. After adding this, the file repository is at revision 6.
[tom@CentOS trunk]$ cat README 
/* TODO: Add contents in README file */

[tom@CentOS trunk]$ svn status
?       README

[tom@CentOS trunk]$ svn add README 
A         README

[tom@CentOS trunk]$ svn commit -m "Added README file. Will update it's content in future."
Adding         trunk/README
Transmitting file data .
Committed revision 6. 
Jerry checks out the latest code which is at revision 6. And immediately he starts working. After a few hours, Tom updates README file and commits his changes. The modified README will look like this.
[tom@CentOS trunk]$ cat README 
* Supported operations:

1) Accept input
2) Display array elements

[tom@CentOS trunk]$ svn status
M       README

[tom@CentOS trunk]$ svn commit -m "Added supported operation in README"
Sending        trunk/README
Transmitting file data .
Committed revision 7.
Now, the repository is at revision 7 and Jerry's working copy is out of date.Jerry also updates the README file and tries to commit his changes.
Jerry's README file looks like this.
[jerry@CentOS trunk]$ cat README 
* File list

1) array.c Implementation of array operation.
2) README Instructions for user.

[jerry@CentOS trunk]$ svn status
M       README

[jerry@CentOS trunk]$ svn commit -m "Updated README"
Sending        trunk/README
svn: Commit failed (details follow):
svn: File or directory 'README' is out of date; try updating
svn: resource out of date; try updating

Step 1: View Conflicts

Subversion has detected that the README file has changed since last updated. So, Jerry has to update his working copy.
[jerry@CentOS trunk]$ svn up
Conflict discovered in 'README'.
Select: (p) postpone, (df) diff-full, (e) edit,
        (mc) mine-conflict, (tc) theirs-conflict,
        (s) show all options:
Subversion is complaining that there is a conflict with the README file, and Subversion does not know how to solve this. So Jerry chooses the df option to review the conflict.
[jerry@CentOS trunk]$ svn up
Conflict discovered in 'README'.
Select: (p) postpone, (df) diff-full, (e) edit,
        (mc) mine-conflict, (tc) theirs-conflict,
        (s) show all options: df
--- .svn/text-base/README.svn-base Sat Aug 24 18:07:13 2013
+++ .svn/tmp/README.tmp Sat Aug 24 18:13:03 2013
@@ -1 +1,11 @@
-/* TODO: Add contents in README file */
+<<<<<<< .mine
+* File list
+
+1) array.c Implementation of array operation.
+2) README Instructions for user.
+=======
+* Supported operations:
+
+1) Accept input
+2) Display array elements
+>>>>>>> .r7
Select: (p) postpone, (df) diff-full, (e) edit, (r) resolved,
        (mc) mine-conflict, (tc) theirs-conflict,
        (s) show all options:

Step 2: Postpone Conflicts

Next Jerry chooses the postpone(p) options, so that he can resolve the conflict.
Select: (p) postpone, (df) diff-full, (e) edit, (r) resolved,
        (mc) mine-conflict, (tc) theirs-conflict,
        (s) show all options: p
C    README
Updated to revision 7.
Summary of conflicts:
  Text conflicts: 1
After opening the README in text editor he realizes that Subversion has included both Tom's code and his code with conflict markers.
[jerry@CentOS trunk]$ cat README
<<<<<<< .min
* File list

1) array.c Implementation of array operation.
2) README Instructions for user.
=======
* Supported operations:

1) Accept input
2) Display array elements
>>>>>>> .r7
Jerry wants Tom's changes as well as his, so he just removes the lines containing the conflict markers.
So, the modified README will look like this.
[jerry@CentOS trunk]$ cat README
* File list

1) array.c Implementation of array operation.
2) README Instructions for user.

* Supported operations:

1) Accept input
2) Display array elements
Jerry resolved the conflict and he retries commit.
[jerry@CentOS trunk]$ svn commit -m "Updated README"
svn: Commit failed (details follow):
svn: Aborting commit: '/home/jerry/project_repo/trunk/README' remains in conflict
 
[jerry@CentOS trunk]$ svn status
?       README.r6
?       README.r7
?       README.mine
C       README

Step 3: Resolve Conflicts

In the above commit, the letter C indicates that there is a conflict in the README file. Jerry resolved the conflict but didn't tell Subversion that he had resolved the conflict. He uses the resolve command to inform Subversion about the conflict resolution.
[jerry@CentOS trunk]$ svn resolve --accept=working README
Resolved conflicted state of 'README'

[jerry@CentOS trunk]$ svn status
M       README

[jerry@CentOS trunk]$ svn commit -m "Updated README"
Sending        trunk/README
Transmitting file data .
Committed revision 8.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home