Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the simplest way to do branching and merging using TortoiseSVN?

What is a really simple "how to" to do branching and merging using TortoiseSVN?

like image 256
JoelFan Avatar asked Sep 22 '09 18:09

JoelFan


People also ask

How do I merge changes from branch to trunk in SVN?

You want to checkout a working copy of trunk and then use the svn merge --reintegrate option: $ pwd /home/user/project-trunk $ svn update # (make sure the working copy is up to date) At revision <N>. $ svn merge --reintegrate ^/project/branches/branch_1 --- Merging differences between repository URLs into '.


1 Answers

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 repository: 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/MyRepository/MyProj/Trunk, create http://myserver/svn/MyRepository/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/MyRepository/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 (for example, http://myserver/svn/MyRepository/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.)

Whether 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 (for example, http://myserver/svn/MyRepository/MyProj/Trunk). Leave Revision Range blank 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 (for example, http://myserver/svn/MyRepository/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 (for example, http://myserver/svn/MyRepository/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 (for example, http://myserver/svn/MyRepository/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!

like image 196
JoelFan Avatar answered Oct 13 '22 05:10

JoelFan