Compartilhar via


Merge and resolve conflicts when checking files in

Conflicts can occur when you check files in under the following conditions:

  • The date stamp on your file is older than the version that is checked in to the Team Foundation server. This can occur if you get an older version of the file and then try to check it in.

  • Other team members have checked in changes between the time that you got the latest version of the file and the time that you try to check it in. In this case, there are two kinds of changes that can occur, even in the same file:

    • If you changed different lines in the file than the other team members, these are considered simple changes and can be merged automatically using the Auto Merge All feature.

    • If you changed the same lines in the file as other team members, these are considered conflicts. Conflicts are more complex and require manual resolution.

Resolving conflicts can seem complex at first, but it can be helpful to understand the different kinds of file conflicts and the different kinds of resolutions. For more information, see Understanding File Differences and Conflict Types on MSDN. Additionally, this topic can help by describing what you will see when you have to resolve conflicts in Microsoft Expression Blend or Microsoft Visual Studio Team System 2008 Team Explorer.

Using the Resolve Conflicts dialog box

When conflicts occur during a check-in, you initially have two choices:

  • Auto Merge All   Merges the conflicts automatically. The merge options used by the automatic merging feature should already have been configured by the Microsoft Team Foundation server administrator in Visual Studio 2008 Team System.

    The automatic merging feature is available only if you made changes to different lines of the file than other team members did, because in that situation, merging is a simple process. Otherwise, you must resolve conflicts manually.

    Note

    If the conflict was caused by trying to check in an older version of the file, the automatic merging feature typically will not use any content from your older version because the default settings of the automatic merge feature favor the most recent file. For information about the correct way to revert to an earlier version of a file, see How to: Roll Back a Changeset on MSDN.

  • Resolve   Resolves the conflicts manually. The Resolve Version Conflict dialog box will appear, in which you will be given the following additional options:

    • Merge changes for me   Uses the automatic merging feature. This option is disabled if Expression Blend detects that you have changed the same lines in the file as another team member.

    • Merge changes in a merge tool   Prompts you to determine the changes to accept. If this option is selected, the merge tool appears. See the following section, "Using the merge tool."

    • Undo my local changes   Removes the changes that you made to the file, effectively restoring the file's content (but not the datestamp) to the most recent version on the Team Foundation server.

    • Discard server changes   Applies all of your changes only. If you check the file in, you will remove the changes made by other team members while you had the file checked out. This is the option you would use if you wanted to revert to an earlier version of a file. For information about the correct way to revert to an earlier version of a file, see How to: Roll Back a Changeset on MSDN.

      Warning

      Make sure that you inform team members that you are going to undo their changes before you use this option.

    • Compare   Displays a window that compares the differences between any two of the following three versions of the file: your local copy, the copy that was most recently checked by another team member while you had the file checked out, and the original that existed before either one of you checked the file out. Comparing versions is useful in helping you decide whether you want to undo your local changes, discard your server changes, or merge and resolve conflicts using the merge tool.

Tip

As a best practice, remember to run (F5) and check in or undo pending changes to files after you have resolved conflicts, and before you perform any other source control tasks. For example, if you try to get a specific version of a file after resolving conflicts but before you've checked in the file, you will be asked to resolve conflicts again, and the description of the conflict in the Resolve Conflicts dialog box will be "You have a conflicting pending change."

Using the merge tool

The merge tool gives you the most control because you can select individual conflicting lines and apply them to or remove them from the merged file.

At the top of the merge tool, two panes display different versions of the file. The version that was checked in by the other team member while you had the file checked out is displayed on the left, and your local copy (not yet checked in) is displayed on the right. In each pane, colors are used to identify the lines that have been changed from the original version of the file that existed before the other team member checked in his or her changes. Red lines represent text that was deleted, green lines represent text that was inserted, and blue lines represent text that was modified. If there are changes in the same line in both files in the top two panes, this change is considered a conflict.

At the bottom of the merge tool is a third pane. Initially, this bottom pane displays the original version of the file to which the non-conflicting changes from the top two files have been applied.

Ee341461.e39a4383-0828-40ee-9167-8c623611364e(en-us,Expression.30).png

Ee341461.25182a96-9a69-478a-9cfe-5b360e6a9bea(en-us,Expression.30).png

A line changed both in your local version and in the currently checked-in version, resulting in a conflict that must be resolved manually.

Ee341461.05fe4b1d-f584-4bd2-99b6-8bc2d735a89d(en-us,Expression.30).png

The original version of the line that is in conflict.

Ee341461.095c13e8-6ed8-4572-9bd2-b2d6bdfdf199(en-us,Expression.30).png

A line that was added by you and is already applied to the merged file below.

Ee341461.e1a62fcf-2f5c-4263-95fe-a9bf97616b85(en-us,Expression.30).png

A line changed in the most recent check-in that is not in conflict with your changes. This line is already applied to the merged file below and cannot be removed.

Ee341461.b36987f6-e914-4b58-99f2-a76c47128837(en-us,Expression.30).png

A line removed in the currently checked-in version. You cannot undo this change because it is not in conflict with your local version.

Conflicts, identified in the bottom pane by a bounding rectangle, must be resolved manually. To accept the change from one of the two files at the top, do one of the following:

  • Click the line whose change you want to apply to the file at the bottom (see the following image).

  • Right-click the line whose change you want to apply, and then click Apply Change.

  • Right-click the original line in the file at the bottom, and then click Apply Change on the Left or Apply Change on the Right.

To remove a change that you've applied, do one of the following:

  • Click a line whose changes have already been applied from one of the files at the top.

  • Right-click a line whose changes have already been applied from one of the files at the top, and then click Remove Change.

  • Right-click the original line in the file at the bottom, and then click Remove Changes for This Conflict.

After you apply or remove conflicts from the top two panes, the bottom pane is updated to display the results of the choices that you make.

Ee341461.0e425bcd-05cb-4dc5-adb0-7b7daf195889(en-us,Expression.30).png

Ee341461.095c13e8-6ed8-4572-9bd2-b2d6bdfdf199(en-us,Expression.30).png

One of the lines in conflict. Click the line that you want to apply to the merged file.

Ee341461.e1a62fcf-2f5c-4263-95fe-a9bf97616b85(en-us,Expression.30).png

The updated version of the line that is in conflict.

If you Apply Both Changes, both lines will appear in the bottom pane, which can cause build errors, but doing so can be useful when you want to compare both lines visually in the bottom pane. You can always remove one of the lines from the bottom pane when you are done comparing.

At any time, you can apply all the lines that are in conflict from the server version of the file or from your local file by right-clicking inside the merge tool, pointing to Resolve All Conflicts, and then clicking either With changes on the Left or With changes on the Right. This applies only the lines that are in conflict; it does not remove the changed lines that were not in conflict.

After you click OK to exit the merge tool, click Yes to save the file, and click Close to exit the Resolve Conflicts dialog box, remember to test your merged file by building (CTRL+SHIFT+B) or running (F5) your solution before checking the file in.

You can find a short procedure for using the merge tool at How to: Resolve Conflicts Between Two Files on MSDN.

Viewing the list of files that have conflicts

If you try to check in files and then close the Resolve Conflicts dialog box without resolving any of the conflicts, the source control system keeps track of those files. At any time, you can right-click the solution in the Projects panel, and then click Resolve Conflicts to see all the files that still have unresolved conflicts.

See also

Tasks

View or compare the changes made to files

Check files in and out