'SVN Merge of Moved Source Code Files

I feel like I have the simplest use case in the world with SVN:

  • I have a file, Test.java in trunk of SVN.
  • I branch trunk to dev-branch.
  • I move Test.java into com/mycompany folder in trunk.
  • I change Test.java in dev-branch.
  • I merge dev-branch to trunk.
  • Tree conflict results.

Why, oh why, can't SVN handle this? Are we doing something wrong? This feels like it should be easy and yet every engineer at my company is stymied.

Looking for SVN-oriented answers here (not 'move to git', etc).



Solution 1:[1]

In SVN a move is a delete and an add. When you merged in the branch it would do the add part of your move, but it couldn't do the delete because of the conflict. You now have to resolve the conflict manually by

  1. Copying your Test.java to com/mycompany/Test.java, overwriting the old one. That resolves the conflict with that file.
  2. Delete the Test.java file from the old place. That is the manual way to do the delete part of the change set that SVN couldn't do when you did your merge. Use the svn delete Test.java command.
  3. Tell SVN the conflict is resolved and that your working directory is correct with svn resolve --accept working . The dot at the end is for the current directory
  4. Tell SVN that the Test.java file's conflict is also resolved with svn resolve --accept working Test.java

Then you can commit your merged version and you are back in sync with the repository.

Solution 2:[2]

In SVN 1.14, this merge should work fine. SVN will be able to detect the moved folder in trunk. So simply doing a merge would have been fine.

But if this is not the case, the alternative would be to merge the trunk 'tree change' into the branch first and then merge the branch into trunk again. So basically you align the branch with the newest changes in trunk (so the folder would have been created and the file moved into it), and then only merge back to trunk.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David Harkness
Solution 2 Wasted_Coder