tags:

views:

741

answers:

2

Hi all,

A few weeks ago I started making a change in my SVN repository's trunk that I thought was going to be fairly minor.

After a few hours of work, realizing that the change had bigger implications than I thought, I decided it was too risky to check my changes into the trunk right away, so I made a branch, like this:

svn copy . https://my_svn_server/svn/blah/branches/my-branch

... and then did a svn switch and happily continued working in that branch. So far, so good, until I get to the point where I'm happy with all the changes and want to merge them back into the trunk again. So I check in all the changes into my-branch, and then carefully follow the procedure shown here ... and here is where I ran into trouble. Because I created my-branch from the local (client-side) repository that already had a large number of (not-checked-in) changes outstanding in it, the merge doesn't include the diffs corresponding to those changes, and thus there are lots and lots of conflicts in the merge that I have to resolve by hand -- something I don't want to do since it leaves room for bugs to creep in if I mess it up.

I tried including the missing diffs by decrementing the revision number I specify during the merge, e.g. by doing a

svn merge -r2818:2932 https://my_svn_server/svn/blah/branches/my-branch

instead of the expected

svn merge -r2819:2932 https://my_svn_server/svn/blah/branches/my-branch

...but that didn't work, because my-branch didn't exist at revision 2818, and so I just get an error:

svn: Unable to find repository location for 'https://my_svn_server/svn/blah/branches/my-branch' in revision 2818

So that's about where things stand. I can manually sort out the mess this time, but I'm curious if there is a way to handle this so that things go better for me next time.

One way I can think of would be to create my-branch not by copying the local (client-side) respository but rather by making a copy of the SVN trunk HEAD, and then checking out my-branch into a separate directory, and then manually copying my local (not-checked-in) changes from the trunk directory to the my-branch directory, and then reverting the local trunk directly... but that's pretty tedious and error-prone as well.

Surely there is a better, more automatic way to make a branch that contains local (not-checked-in) changes, and later merge it back into the trunk?

+6  A: 

Your last suggestion is almost there. When you want to branch, copy the trunk HEAD. Then in your working copy,

svn switch https://my_svn_server/svn/blah/branches/my-branch

This will switch you to the branch, while keeping all your local modifications. You can then commit your changes to the branch whenever you want to.

bobDevil
Cool, I didn't realize svn switch would keep my local edits. That's the thing I was missing :^)
Jeremy Friesner
Hmm, well, it'll *try* to keep your local edits.
Jim T
My answer was made under the assumption that the trunk HEAD is identical to the new branch HEAD. I make no guarantees it will successfully keep your local edits if you have some other changes that conflict in the trunk.
bobDevil
+1  A: 

Okay, I think I've figured how to do the merge cleanly (funny how composing a question often clarifies the problem, isn't it?). The solution is to do two merges, one to account for the diffs between the main branch (as it was) and the beginning of my-branch, and then the second merge to account for the subsequent changes made in my-branch:

svn merge https://my_svn_server/svn/blah/trunk/software@2818 https://my_svn_server/svnblah/branches/my-branch@2819
svn merge -r2819:2932 https://my_svn_server/svn/blah/branches/my-branch
Jeremy Friesner