'How do I handle an SVN merge after I have moved some directories in a branch?

Suppose I have the following:

trunk/
|-+ d1/
| |-- bar.c
| \-- foo.c
\-+ d2/
  \-- baz.txt

I do svn cp trunk branch, and commit.

Now, I do some cleanup in branch.

$ svn mkdir src
$ svn mv d1 src/
$ svn commit
$ edit src/d1/foo.c
$ svn commit

This leaves me with the following in branch

branch/
|-+ d2/
| \-- baz.txt
\-+ src/
  \-+ d1/
    |-- bar.c
    \-- foo.c

Meanwhile, some changes have occurred in trunk (editing foo.c and bar.c).

Now, philosophically, I want branch's directory structure to be reflected in trunk, and I want the edits I've made to its files there too. But I also want the edits that happened in trunk while I was working. So I want to merge the contents of trunk/d1/foo.c and branch/src/d1/foo.c.

Merging in either direction (trunk to branch or branch to trunk) gives me a ton of tree conflicts. Is there a better way to proceed than running svn info on every conflict and resolving things carefully and manually?

svn


Solution 1:[1]

This sounds like a candidate for "bunny hopping."

http://designbygravity.wordpress.com/2009/10/19/what-mother-never-told-you-about-svn-branching-and-merging/

Solution 2:[2]

@lvmisooners answer is out-of-date now; per the comments in that blog, the whole article is irrelevant since SVN 1.5.

In general, merge from trunk to branch often. Then eventually --reintegrate the branch into the trunk and never use that branch again, per http://svnbook.red-bean.com/en/1.7/svn.branchmerge.advanced.html Actually, you can reuse the branch if you follow the Keeping a Reintegrated Branch Alive trick on that page.

Solution 3:[3]

In SVN 1.14, this merge would be possible. When you make directory changes in a branch, you can merge those "changes" to the trunk. SVN will mirror your directory movements on the trunk and also commit any other changes on the way.

The only catch is that you should not have movement on the trunk as well on the same folders as in branch. This will create conflicting movements.

In this case you will just need to ensure you merge all the movement revisions of this branch (maybe a complete sync merge) to trunk. If you merge changes only from the branch to the trunk SVN will not be able to "know" the original folder on the trunk, but it will try to "figure it out" and if the move was not complicated (like having 2 moves on a folder in the branch) it would get it right. I'm not sure where the limit lies with SVN's ability to track movement on the folders, but it does fail easily and then resolving the conflicts does not give you the option to point the changes to a different target folder. It just allows you to ignore the changes.

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 Scott Coldwell
Solution 2 CrazyPyro
Solution 3 Wasted_Coder