Merging Files and Folders (Team Explorer Everywhere)

If you merge files, you combine changes that were made in two distinct branches. For example, you might add, edit, rename, delete, or undelete a file in the source branch. A merge operation integrates those kinds of changes into the target branch. If items have been modified in both the source and target branches, you are prompted to resolve the conflicts.

You can merge files from Source Control Explorer or by using the Merge command.

During a merge operation, the following events occur:

  • The operation identifies any added files or folders in the source branch and tries to add the corresponding items to the target branch.

    Note

    If you try to merge items that have the same name in both branches, Team Foundation performs an implicit baseless merge. However, if you use the -noimplicitbaseless option with the tf merge command, the namespace conflict cannot be resolved by using a baseless merge. You must rename one of the files and run the merge operation again to resolve the conflict. For more information about implicit baseless merges, see Merge Command.

  • The operation reviews the history for each item that exists in both branches. For each item, changes that were made in the source branch but not the target branch are merged into the target branch. If the item has already been modified on the target branch, a conflict is reported. For information about how to resolve merge conflicts, see Resolve Conflicts between Two Files (Team Explorer Everywhere).

  • When you perform a merge operation, you have the choice of merging either specific versions of items or all changes.

Team Foundation version control keeps a record of all merges. You can review this information at a command prompt by using the Merges command.

In this topic

  • Initiate a Merge Operation from Source Control Explorer

  • Initiate a Merge Operation from a Command Prompt

Required Permissions

To perform these procedures, you must have the following permissions set:

  • You must have the Read permission for the item in the source tree, and your Check out permission for the item in the target tree must be set to Allow.

  • You must have the Merge permission for the target path.

  • If the item in the target tree is being renamed, your Check out permission for both the source tree and the target tree must be set to Allow.

  • If any files that are affected by the operation are locked, your Lock permission must be set to Allow.

For more information, see the following page on the Microsoft website: Team Foundation Server Permissions.

Initiate a Merge Operation from Source Control Explorer

Important

The release of Visual Studio Team Foundation Server 2010 started a distinction between branches and folders. For example, the following illustration shows how different icons indicate branches and folders.

A branch and a folder

You can still branch and merge among folders, but the best practice is to branch and merge only among branches. For more information, see Branching Files and Folders (Team Explorer Everywhere).

To merge branches, files, and folders from Source Control Explorer

  1. In Source Control Explorer, right-click the branch, folder, or file that you want to merge, and then click Merge.

    The Source Control Merge Wizard appears.

  2. In Source branch, either type the name of the source branch, or click Browse to specify one from the list.

  3. Click either All changes up to a specific version or Selected changesets to specify the range of changes that you want to merge.

    By clicking All changes up to a specific version, you reduce the risk of conflicts in future merges.

  4. In Target branch, specify the branch of the project into which you want to merge changes, and then click Next.

    The Select versions page appears.

  5. In the Version type list, click one of the following options:

    • If you click Latest Version, the branch is created for the most recent version in version control.

    • If you click Changeset, you can specify the number of the changeset in the Changeset box. As an alternative, click the ellipses (...) to open the Find Changesets dialog box.

      For more information, see Search for a Changeset.

    • If you click Label, you can type the label name in the Label box. As an alternative, you can also click the ellipses (...) to open the Find Label dialog box.

      For more information, see List, Find, View, Edit, and Remove Labels.

    • If you click Date, you can specify a date in the Date box.

    • If you click Workspace Version, you can specify a computer and a Team Foundation Server workspace in the Workspace box.

  6. Click Next, and then, on the Perform the merge operation page, click Finish.

  7. (Optional) Check in the pending changes.

    For more information, see Check in Pending Changes (Team Explorer Everywhere).

Initiate a Merge Operation from a Command Prompt

You can use the tf merge command to apply changes in an existing source branch to an existing target branch. You can merge an individual revision or a complete changeset to the target branch. You can merge changes from the source to the target branch or from the target to the source branch.

Baseless Merge

You can use the tf merge command to perform a baseless merge, that is, to merge items that are not directly branched from each other. When you perform a baseless merge, Team Foundation does not have any information about the relationships between the files in the branches. In a baseless merge, you must resolve conflicts manually. After you have performed the baseless merge and resolved any conflicts, Team Foundation records the merge history and establishes a relationship between the folders and files.

When you use the tf merge command, Team Foundation performs an implicit baseless merge between items that have the same relative name in two previously related version-controlled trees. For example, you might want to merge the related branches SRC and TGT. Both branches contain an unrelated file that is named a.txt. When you run tf merge, Team Foundation establishes a relationship between the two a.txt files if the two files are the same and the source file is not related to any other file in the target branch.

If you run tf merge and specify the -noimplicitbaseless option, the two a.txt files will create a namespace conflict when you try to check in the changes. To resolve the conflict, you must rename one of the files.

To view a list of changesets that have not been merged

  • At a command prompt, type tf merge –candidate Source Destination -recursive, and then press ENTER.

    Replace Source with the name of the source branch, and replace Destination with the name of the branch into which you want to merge changes.

    For more information, see the following page on the Microsoft website: Merge Command (Team Foundation Version Control).

To merge a folder or file at a command prompt

  • At a command prompt, type tf merge Source Destination -recursive, and then press ENTER.

    Replace Source with the name of the source file or folder from which you want to merge changes. Replace Destination with the name of the branch into which you want to merge changes.

    For more information, see the following page on the Microsoft website: Merge Command (Team Foundation Version Control).

See Also

Other Resources

Branching and Merging (Team Explorer Everywhere)

Branching Files and Folders (Team Explorer Everywhere)

Associate a File Type with a Merge Tool (Team Explorer Everywhere)