Branching and Merging with TortoiseSVN

Posted by capgpilk on ASP.net Weblogs See other posts from ASP.net Weblogs or by capgpilk
Published on Wed, 19 May 2010 19:03:35 GMT Indexed on 2010/05/19 19:10 UTC
Read the original article Hit count: 456

For this example I am using Visual Studio 2010, TortoiseSVN 1.6.6, Subversion 1.6.6 and AnkhSVN 2.1.7819.411, so if you are using different versions, some of these screen shots may differ.

This is assuming you have your code checked in to the trunk directory and have a standard SVN structure of trunk, branches and tags. There are a number of developers who prefer to develop solely in a branch and never touch the trunk, but the process is generally the same and you may be on a small team and prefer to work in the trunk and branch occasionally.

There are three steps to successful branching. First you branch, then when you are ready you need to reintegrate any changes that other developers may have made to the trunk in to your branch. Then finally when your branch and the trunk are in sync, you merge it back in to the trunk.

Branch

  1. Right click project root in Windows Explorer > TortoiseSVN > Branch/Tag
    1 - 1

  2. Enter the branch label in the ‘To URL’ box. For example /branches/1.1
    1 - 2

  3. Choose Head revision
  4. Check Switch working copy
  5. Click OK
  6. Make any changes to branch
    1 - 3

  7. Make any changes to trunk
    1 - 4

  8. Commit any changes
    1 - 5

For this example I copied the project to another location prior to branching and made changes to that using Notepad++. Then committed it to SVN, as this directory is mapped to the trunk, that is what gets updated.

 

Merge Trunk with Branch

  1. Right click project root in Windows Explorer > TortoiseSVN > Merge
    2 - 1

  2. Choose ‘Merge a range of revisions’
    2 - 2

  3. In ‘URL to merge from’ choose your trunk
    2 - 3

  4. Click Next, then the ‘test merge’ button. This will highlight any conflicts. Here we have one conflict we will need to resolve because we made a change and checked in to trunk earlier
    2 - 4


    2 - 5
  5. Click merge. Now we have the opportunity to edit that conflict
    2 -5 - a

  6. This will open up TortoiseMerge which will allow us to resolve the issue. In this case I want both changes.
    2 -5 - b


    2 -5 - c


    2 -5 - d

  7. Perform an Update then Commit
    2 - 7 - a


    2 - 7 - b

  8. Reloading in Visual Studio shows we have all changes that have been made to both trunk and branch.2 - 8

Merge Branch with Trunk

  1. Switch working copy by right clicking project root in Windows Explorer > TortoiseSVN > switch3 - 3

  2. Switch to the trunk then ok
    3 - 4

  3. Right click project root in Windows Explorer > TortoiseSVN > merge
    3 - 5

  4. Choose ‘Reintegrate a branch’
    3 - 6

  5. In ‘From URL’ choose your branch then next
    3 - 7

  6. Click ‘Test merge’, this shouldn’t show any conflicts
    3 - 8

  7. Click Merge
  8. Perform Update then Commit
    3 - 10


    3 - 10 - a

  9. Open project in Visual Studio, we now have all changes.

So there we have it we are connected back to the trunk and have all the updates merged.

© ASP.net Weblogs or respective owner

Related posts about .NET

Related posts about Continuous Integration