+++ date = "2007-07-04" title = "How to resolve Subversion Conflicts" tags = ["Subversion", "conflicts"] slug = "how-to-resolve-subversion-conflicts" description = "Got a merge conflict on Subversion. Don't panic, here's what to do." +++ If there's more than one person working on a project, chances are (although slim) that at some point two developers work on the same piece of code and check it in. To clarify, let me give you an example. The repository is currently at revision 5 and contains a file named 'README'. Revision 5 of that file contains a single line: 'This is a README file'. Now, both you and your colleague check out r5 and edit README. Your colleague changes the line to 'This is a documentation file' and commits it back to the repository, which is bumped to revision 6. You're an island, and have no clue about the new revision being created. You just happily write away and change the README file to: 'This is fun stuff!'. When you commit your changes, you'll get an error message: ``` shell $ svn commit -m "Updated README" Sending README Transmitting file data .svn: Commit failed (details follow): svn: Out of date: '/myproject/README' ``` This is good. Subversion has detected that the file you want to commit has changed since you last updated it. Update the file to get it up-to-date again. ``` shell $ svn update C README Updated to revision 6. ``` The 'C' indicates there is a conflict with the README file, and Subversion does not know how to solve this. You are called in to help. If you now take a look at README, you'll notice that there are several markers that indicate what parts of the code are conflicting. You can easily see what you changed, and what has changed in the repository: ``` shell <<<<<<< .mine This is fun stuff! ======= This is a documentation file >>>>>>> .r6 ``` ## What are your options? You have three options for resolving the conflict. Whatever you choose, make sure you confer with your colleague on the matter. 1. Scrap your changes, and go with the current work from your colleague. This is the easiest solution. All you have to do is revert the changes you made, and update your working copy: ``` shell $ svn revert README Reverted 'README' $ svn update README At revision 6. ``` 2. Keep your changes, and dump whatever your colleague did. Performing a simple 'ls' will show you that there are four files related to this conflict: