Export (0) Print
Expand All

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.

Before you can complete this walkthrough, you must:

Required Permissions

To complete this walkthrough, you must have the PendChange and CheckIn permissions.

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.

Caution noteCaution:

The following procedures assume that you have already completed the steps in Walkthrough: Exploring Team Foundation Version Control.

To branch items in version control

  1. On the View menu, click Other Windows, and then click Source Control Explorer to open it.

  2. 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.

  3. 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.

    NoteNote:

    Target branches are automatically appended with the string "-branch".

  4. In the Branch from version section, in the By drop-down list, select Latest Version.

  5. Click OK.

    Team Foundation version control creates the new branch and displays it in Source Control Explorer.

  6. 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.

  7. 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.

  8. In the Check In dialog box, in the comment text box, type Test branch and click Check In.

    NoteNote:

    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

  1. 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.

  2. In the Check Out dialog box, click Check Out.

    Source Control Explorer now displays the file's Pending Change status as edit.

  3. Double-click the Class1.cs file to open it for editing.

  4. 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";
          }
    } 
    
  5. From the File menu, click Save Class1.cs.

  6. In Source Control Explorer, right-click the Class1.cs file, and select Check In Pending Changes.

  7. In the Check In dialog box, in the comment text box, type New branch changes, and then click Check In.

    NoteNote:

    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.

  8. In Source Control Explorer, open the folder that contains the original branch called MyWindowsApp.

  9. 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.

  10. In the Check Out dialog box, click Check Out.

    Source Control Explorer now displays the file's Pending Change status as edit.

  11. Double-click the Class1.cs file to open it for editing.

  12. 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";
          }
    } 
    
  13. From the File menu, click Save Class1.cs.

  14. In Source Control Explorer, right-click the Class1.cs file, and select Check In Pending Changes.

  15. In the Check In dialog box, in the comment text box, type Original branch changes, and click Check In.

    NoteNote:

    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.

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

  1. 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.

  2. In the Target Branch drop-down list, select the MyWindowsApp folder.

  3. In Select the source branch changes you want to merge, select All changes up to a specific version, and click Next.

  4. In the Select the version of the source items step, in the Version Type drop-down list, select Latest Version, and click Next.

  5. 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

  1. In the Resolve Conflicts dialog box, click Resolve.

    The Resolve Version Conflict dialog box appears.

  2. In the Resolve Version Conflict dialog box, in Resolution Options, select Merge changes in merge tool, and click OK.

  3. 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.

  4. Click the code that contains the string New branch.

    The merge tool displays the change in the bottom pane.

  5. Click OK.

  6. In the Microsoft Visual Studio dialog box, click Yes to save the file.

  7. You will be prompted to accept the merged results. Click Yes to keep the merged file.

  8. In the Resolve Conflicts dialog box, click Close.

  9. In Source Control Explorer, right-click the MyWindowsApp folder, and select Check In Pending Changes.

    The Check In dialog box appears.

  10. In the Check In dialog box, click Check In.

    NoteNote:

    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.

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

  1. In Source Control Explorer, open the MyWindowsApp Test Branch folder created in the earlier procedure, right-click it, and select Apply Label.

  2. In the Choose Item Version dialog box, select the MyWindowsApp Test Branch folder.

  3. Set the Items of type box to All files (*.*), and then click OK.

  4. In the Apply Label dialog box, in the Name text box, type MyWindowsApp label test.

  5. In the Comment text box, type All files for building version of MyWindowsApp.

  6. Under Items, click Add.

  7. In the Choose Item Version dialog box, make sure that the Look in list contains the team project you are working on.

  8. Navigate in the MyWindowsApp Test Branch folder to locate the Class1.cs file, and then select it.

  9. In the Version list, select Latest Version.

  10. Click OK.

    Team Foundation version control displays the Apply Label dialog box with the items populated.

  11. Click OK.

Community Additions

ADD
Show:
© 2015 Microsoft