views:

3649

answers:

2

I have not found a really simple "how to" any where so I came up with my own through trial and error and wanted to share it, i.e. I will answer this question myself.

+24  A: 

Assuming your work directory is working from the Trunk:

Right-click on the "root work folder" (this term always refers to Windows Explorer) and do "svn update" to update your work folder to the latest Trunk.

Make sure what you have is stable.

Right-click on the root work folder and do "svn commit" to make sure any local changes are committed to the Trunk.

Right-click on the root work folder and do "svn repo-browser".

If you don't already have a Branches folder in the Repo: right-click on the folder just above the Trunk folder and do "create folder" and create a Branches folder (For example, if your Trunk is http://myserver/svn/myrepo/MyProj/Trunk, create http://myserver/svn/myrepo/MyProj/Branches).

Right-click on the Trunk folder and do Copy To: and put in the new folder name for your branch. For example: http://myserver/svn/myrepo/MyProj/Branches/MyNewBranch. (Don't worry that this will waste a lot of space... this is called a "cheap copy" ... it doesn't actually copy the contents of files unless they change).

Close repo-browser.

Right click your work folder root, and do: "svn switch" and choose the folder name of your new branch (e.g. http://myserver/svn/myrepo/MyProj/Branches/MyNewBranch). Leave everything else at the default.

Now work on your branch. When you get to milestones, right-click on the root work folder and do "svn commit" to commit to your Branch. (This will not be seen in the Trunk).

If others are working on the same Branch, periodically do "svn update" from the root work folder. This will update from the Branch. (It will NOT get any updates from the trunk.)

Weather or not others are working on the same branch, you should periodically merge changes from the Trunk to make sure your Branch won't be too hard to integrate later. To do the periodic merge: right-click on the work folder root and do "svn merge". Select "Merge a Range of Revisions". Under "URL to merge from", choose the Trunk (e.g. http://myserver/svn/myrepo/MyProj/Trunk). Leave Revision Range blank and and leave everything else alone. Click Next. Leave everything alone and click Merge. Make sure everything still works... fix it if not. Once you are satisfied, do a regular "svn update" from the work root folder to update from the Branch (this is necessary even if you are the only one working on the branch, to satisfy svn). Then do "svn commit" to commit the merged Trunk changes to the Branch. You can repeat this step periodically as many times as you want.

Once your Branch is ready to integrate, do the above step one last time and do your final testing. Do a final commit to the Branch.

Right click on your root work folder and do another "svn switch", this time switching to the Trunk (e.g. http://myserver/svn/myrepo/MyProj/Trunk). This will have the effect of essentially "undoing" all the work you've done on your branch, but don't worry... you will get your work back. (It will also report a lot of updates to files you didn't change in your Branch, but these are just "svn property" changes... don't worry about them.)

Right click on your work folder and do "svn merge". This time, choose "Reintegrate a Branch". For the URL, put in your branch (e.g. "http://myserver/svn/myrepo/MyProj/Branches/MyNewBranch"). Leave the rest alone and click Next. Leave everything alone and click Merge. You now have all the work you've done on your Branch, as well as up-to-date work from the trunk.

Do a final test. Everything should work because this should be the same set of files you had in your last test in the Branch. Right-click on your root work folder and do an "svn commit". Commit everything, even files that you didn't work on in your Branch (they just have "svn property" changes but committing them helps svn keep track of all the revisions).

The Trunk now has all your Branch work as well as all the work that was done in the Trunk while you were working on your Branch, and it all works. In addition, svn has the complete history of all the files, even the revisions that were checked in while you were working on your Branch.

Optional: go into repo-browser, right-click on your Branch folder (e.g. "http://myserver/svn/myrepo/MyProj/Branches/MyNewBranch") and do "delete". This will have no effect on the Trunk and you don't need the Branch any more. (Even if you are really paranoid, don't worry, because you can even get your deleted Branch back from repo browser at any time if you really need to.)

Please feel free to comment!

JoelFan
725 words is simple?
RedFilter
I said "simplest" not "simple" :)
JoelFan
This has been very helpful, thank you!
Funka
Thanks! You've been the first to actually thank me (although there have been upvotes and favorites :)
JoelFan
Is it correct that once you have re-integrated the branch into the trunk, you cannot perform any more work on that branch? As it won't track changes and you won't be able to merge to/from that branch anymore?
Michael Waterfall
As far as I understand, the merge will not work more than once from the same branch.
JoelFan
See: http://blogs.open.collab.net/svn/2008/07/subversion-merg.html for full details on why a branch should be deleted after reintegrating to trunk. I recommend reading the whole post, but the reasoning for deleting the branch is in the "Reflective/Cyclic Merges" and "Branch Management and Reintegrate" sections of the post.
Joshua McKinnon
+1  A: 

I find that I get a large number of false conflicts if I leave Revision Range blank. My recommendation is to use the range from when you created the branch. For example, if the earliest revision of any file in my branch is 250, then I would use a range of "250-HEAD".

Nelson