Walkthrough: Advanced Functionality of Version Control
This walkthrough shows you how to use branches, merges, and labels in Team Foundation version control.
Before you begin this walkthrough, you should have a fundamental understanding of branching, merging, and applying labels to version control items.
Branching Branching in Team Foundation version control copies a specified set of files and folders stored on the server that runs Team Foundation Server to a new location known as a branch. In essence, a branch creates new folders or files that are based on existing ones. Branching preserves the history of the folders and files that you are branching. It enables changes to be merged from the old files to the new ones. Branching can be conducted through Source Control Explorer, or from the command line using the Branch Command. For more information, see Understanding Branching.
Merging The merge process combines two distinct versions of files, folders, or team projects located in separate branches. One branch is the source branch and the other is the target branch. The source branch contains the items that you want to merge into the target branch. These folder and file versions can be based on changesets, dates, labels, workspaces, or the latest version. For more information, see Understanding Branching. You can conduct merges through Source Control Explorer, or from the command line using the Merge Command.
Labeling A label is a marker that you can attach selectively to a set of otherwise unrelated files and folders in your version control server. Labels make it easier to retrieve a specific collection of items to a workspace for either development or build purposes.
This topic shows you how to perform a branch operation and then edit a team member's files in the resulting branch and also the original branch. These edits will then be checked in and merged. The merge will identify conflicts. You must then resolve these conflicts. Finally, you will apply labels to a changeset.
Prerequisites
Before you can complete this walkthrough, you must:
Specify a server that runs Team Foundation Server. For more information about how to connect to Team Foundation, see How to: Connect to Team Foundation Server.
Open an existing team project. For more information, see Walkthrough: Joining a Team Project.
Add the project to version control and thereby create a local workspace in which to store, edit, and test your version-controlled files.
Create a Visual Studio solution and then perform a version control check-in on it. For more information, see Adding Projects and Solutions to Version Control from Solution Explorer.
Conduct the steps in Walkthrough: Exploring Team Foundation Version Control.
Required Permissions
To complete this walkthrough, you must have the PendChange and CheckIn permissions.
Branching Version Control Items
The following procedure describes how to perform a branch operation. Branching is a Team Foundation version control function designed to create new folders or files that are based on existing ones. For more information, see Understanding Branching and How to: Branch Files and Folders.
Warning
The following procedures assume that you have already completed the steps in Walkthrough: Exploring Team Foundation Version Control.
To branch items in version control
On the View menu, click Other Windows, and then click Source Control Explorer to open it.
In Source Control Explorer, open the MyWindowsApp folder that contains the MyWindowsApp.sln solution file that you created in Walkthrough: Exploring Team Foundation Version Control, right-click it, and then select Branch.
In the Branch dialog box, in the Target text box, modify the location and name for the new branch by appending the end with Test Branch. You can also click Browse to find a location.
Note
Target branches are automatically appended with the string "-branch".
In the Branch from version section, in the By drop-down list, select Latest Version.
Click OK.
Team Foundation version control creates the new branch and displays it in Source Control Explorer.
Double-click the new branch folder that is named MyWindowsApp Test Branch.
Notice that, under the Pending Change column, each item in the new branch has a status of branch.
Since a branch is a pending change, you must perform a check-in to apply the branch. Right-click the MyWindowsApp Test Branch folder and select Check In Pending Changes.
In the Check In dialog box, in the comment text box, type Test branch and click Check In.
Note
If your team project has check-in policies in effect, you might have to associate work items or check-in notes before continuing. For more information, see How to: Associate Work Items with Changesets and How to: Associate Check-in Notes with Changesets.
The Pending Change column in Source Control Explorer displays blank entries. This indicates that your new branch is checked in.
You have now successfully created a new branch and checked it in. In the next procedure, you will change files in both the original and new branches.
Apply Some Changes to the Branches
Next, you will make separate but conflicting changes to the same file in both branches. Later, you will merge both branches and resolve the merge conflicts. The following procedure shows you how to check out and edit files in both branches.
Check out and edit some files in the version control branches
In the new branch you created in the previous procedure, expand the MyWindowsApp Test Branch folder. In the right pane, locate the Class1.cs file that you created in Walkthrough: Exploring Team Foundation Version Control, right-click it, and then select Check Out For Edit.
In the Check Out dialog box, click Check Out.
Source Control Explorer now displays the file's Pending Change status as edit.
Double-click the Class1.cs file to open it for editing.
In the Class1.cs file, add the following highlighted code:
using System; using System.Collections.Generic; using System.Text; namespace MyWindowsApp { class Class1 { string SourceControlMerge = "New branch"; } }
From the File menu, click Save Class1.cs.
In Source Control Explorer, right-click the Class1.cs file, and select Check In Pending Changes.
In the Check In dialog box, in the comment text box, type New branch changes, and then click Check In.
Note
If your team project has check-in policies in effect, you might have to associate work items or check-in notes before continuing. For more information, see How to: Associate Work Items with Changesets and How to: Associate Check-in Notes with Changesets.
The Pending Change column in Source Control Explorer displays a blank entry for the Class1.cs file. This indicates that your edits have been checked in.
Now, you will make changes to the original branch. The steps are basically the same as you just completed.
In Source Control Explorer, open the folder that contains the original branch called MyWindowsApp.
In the original branch, expand the MyWindowsApp folder. In the right pane, locate the Class1.cs file that you created in Walkthrough: Exploring Team Foundation Version Control, right-click it, and select Check Out For Edit.
In the Check Out dialog box, click Check Out.
Source Control Explorer now displays the file's Pending Change status as edit.
Double-click the Class1.cs file to open it for editing.
In the Class1.cs file, add the following highlighted code:
using System; using System.Collections.Generic; using System.Text; namespace MyWindowsApp { class Class1 { string SourceControlMerge = "Original branch"; } }
From the File menu, click Save Class1.cs.
In Source Control Explorer, right-click the Class1.cs file, and select Check In Pending Changes.
In the Check In dialog box, in the comment text box, type Original branch changes, and click Check In.
Note
If your team project has check-in policies in effect, you might have to associate work items or check-in notes before continuing. For more information, see How to: Associate Work Items with Changesets and How to: Associate Check-in Notes with Changesets.
The Pending Change column in Source Control Explorer displays a blank entry for the Class1.cs file. This indicates that your edits have been checked in.
Now that you have successfully created a branch and made changes to both the original and new branches, the next procedure shows you how to merge the changes from both branches.
Merging Version Control Items
After you make changes to files in the branches, you can conduct a merge. The following procedure shows you how to use Source Control Explorer for a merge. For more information, see Understanding Merging and How to: Merge Files and Folders.
To merge branches in version control
In Source Control Explorer, right-click the MyWindowsApp Test Branch folder, and select Merge.
In the Source Control Merge Wizard, in the Source Branch text box, the path and name for the MyWindows App Test Branch folder appears.
In the Target Branch drop-down list, select the MyWindowsApp folder.
In Select the source branch changes you want to merge, select All changes up to a specific version, and click Next.
In the Select the version of the source items step, in the Version Type drop-down list, select Latest Version, and click Next.
In the Perform the merge operation step, click Finish.
Since there are differences between the source and target branches, the Resolve Conflicts dialog box appears. Follow the steps in the next procedure to resolve the conflicts. If there are no conflicts, the Resolve Version Conflict dialog box will not appear.
Resolving Merge Conflicts
Since there are differences among files in both branches, you are prompted to take action to resolve conflicts between the two branches. For more information, see How to: Resolve Conflicts Between Two Files. To resolve the merge conflicts, follow these steps.
To resolve merge conflicts
In the Resolve Conflicts dialog box, click Resolve.
The Resolve Version Conflict dialog box appears.
In the Resolve Version Conflict dialog box, in Resolution Options, select Merge changes in merge tool, and click OK.
In the merge tool, locate the conflict in the two files by clicking Next Change. The files are presented side by side. They show the two strings (Original branch and New branch) you entered in the previous procedure.
Click the code that contains the string New branch.
The merge tool displays the change in the bottom pane.
Click OK.
In the Microsoft Visual Studio dialog box, click Yes to save the file.
You will be prompted to accept the merged results. Click Yes to keep the merged file.
In the Resolve Conflicts dialog box, click Close.
In Source Control Explorer, right-click the MyWindowsApp folder, and select Check In Pending Changes.
The Check In dialog box appears.
In the Check In dialog box, click Check In.
Note
If your team project has check-in policies in effect, you might have to associate work items or check-in notes before continuing. For more information, see How to: Associate Work Items with Changesets and How to: Associate Check-in Notes with Changesets.
You have now successfully created a branch, made changes to both the original and new branches, merged the two together, and resolved conflicts. The next procedure shows you how to use labels in Team Foundation version control.
Labeling Version Control Items
In Team Foundation version control, a label is a name applied to a specific set of revisions. It is often referred to as a snapshot build. Labels can only apply to one revision of a file. Labels are a simple way to organize a set of files in a revision. For more information, see Working with Labels and How to: Apply Labels.
To apply labels to version control
In Source Control Explorer, open the MyWindowsApp Test Branch folder created in the earlier procedure, right-click it, and select Apply Label.
In the Choose Item Version dialog box, select the MyWindowsApp Test Branch folder.
Set the Items of type box to All files (*.*), and then click OK.
In the Apply Label dialog box, in the Name text box, type MyWindowsApp label test.
In the Comment text box, type All files for building version of MyWindowsApp.
Under Items, click Add.
In the Choose Item Version dialog box, make sure that the Look in list contains the team project you are working on.
Navigate in the MyWindowsApp Test Branch folder to locate the Class1.cs file, and then select it.
In the Version list, select Latest Version.
Click OK.
Team Foundation version control displays the Apply Label dialog box with the items populated.
Click OK.
See Also
Concepts
Working with Version Control Changesets
Reference
Label Command (Team Foundation Version Control)