How To Fix Branches After Migration to TFS2010
Let’s say you’ve just migrated your code from another version control system to TFS2010 by grabbing the old code, copying it into your workspace as is, and then checking it in to TFS as a single massive import. It’s a really easy and common way to do tip migration.
When you do this, you will notice that all your branch relationships are missing and source control will look something like this:
The old system had Trunk branched to Feature X and Version 1, etc, but now there’s no relationships and trying to merge from Trunk to a branch brings up a dialog with no targets.
Bummer, huh? Yeah, but what did you expect would happen? You’ve just imported a bunch of folders from the file system and TFS has no way of knowing that they’re branches.
We need to let it know which folders the branches are and the relationships between them. Here’s how we do it:
Step 1: Convert Folders to Branches
Right click the trunk folder (or whatever your root branch folder is) and convert it to a branch.
It should now look like this:
Do this for all the other target branches you have. e.g. Feature X and Version 1.
Step 2: Perform a Baseless Merge
Next, perform a TFS baseless merge to establish a relationship between the parent branch and the child branches. Don’t worry about the contents, we’re only going to merge the folder, not it’s contents.
TFS baseless merges are performed via the command line, so open up your VS2010 command prompt and do the following:
cd <workspaceFolder>
tf merge /baseless <trunk> <childBranch>
Check in your pending changes.
Step 3 Reparent Child Branches
At this point we have a loose link between the branches but the relationships are still not finalised. We need to fix that.
Select your child branch in Source Control Explorer and from the File menu choose Source Control –> Branching and Merging –> Reparent... NOTE: This is not available via the context menu in Source Control Explorer.
In the dialog box, choose the appropriate branch as the new parent. There generally should only be one, unless you have done multiple baseless merges.
Now look at the properties of your child branch and you should see something like this:
Excellent! If you go to your Trunk branch and in the branch context menu choose View Hierarchy. You should see something like this:
Brilliant. Now we’re all done. You can carry on using TFS as you normally would.
Enjoy!