Conflicts after switching to another branch

Conflicts occur when Subversion is unable to automatically merge two versions of the same file. Usually it happens when:

  • you have local (uncommitted) changes in your working copy and perform an Update or Switch operation;
  • you perform a merge from another branch in your repository.

For example, let's suppose that you're working on trunk and have the file CommonClass.cs with the following content:

namespace OurClassLibrary
{
   public class CommonClass
   {
       public static void foo()
       {
       }
   }
}

Then you make some changes to the foo() method. Now you have locally modified file CommonClass.cs with the following content:

namespace OurClassLibrary
{
   public class CommonClass
   {
       public static void foo(string s)
       {
           System.Console.WriteLine(s);
       }
   }
}

Then you want to switch your working copy to the B1 branch. But the B1 branch contains the new, updated version of the file CommonClass.cs with the following contents:

namespace OurClassLibrary
{
   public class CommonClass
   {
       public static void foo(int i)
       {
           System.Console.WriteLine(i);
       }
   }
}

Please note that your local changes in the foo() method overlaps with changes made to that method in the B1 branch. That's why you will get the file CommonClass.cs in the conflicted state when switch to B1 branch will be performed. It happens because Subversion is unable to automatically merge two versions of the file with the overlapping changes. Note that Subversion doesn't understand your programming language and works with your files as with textual ones.

The content of the conflicted file CommonClass.cs will look somehow like this:

namespace OurClassLibrary
{
   public class CommonClass
   {
<<<<<<< .mine
       public static void foo(string s)
=======
       public static void foo(int i)
>>>>>>> .r9
       {
<<<<<<< .mine
           System.Console.WriteLine(s);
=======
           System.Console.WriteLine(i);
>>>>>>> .r9
       }
   }
}

There are two ways to deal with conflicted files. First of all, you can revert (and lost) your changes in the file CommonClass.cs. The other way is to resolve conflicts manually. For example, you can decide that both changes are important and the resolved version of the file should look like this:

namespace OurClassLibrary
{
   public class CommonClass
   {
       public static void foo(string s, int i)
       {
           System.Console.WriteLine(s);
           System.Console.WriteLine(i);
       }
   }
}

Then you should notify Subversion that all conflicts in the file CommonControls.cs are resolved. You can do this by executing "Resolved" command in the context menu of the Visual Studio. You can also mark files as resolved within TortoiseSVN's Show Changes window.

For further details on resolving conflicted files please consider the following articles:

Last Modified: