How to Resolve Merge Conflicts

- J.D. Meier, Jason Taylor, Alex Mackman, Prashant Bansode

To resolve merge conflicts, you use the Visual Studio merge tool. If a conflict is detected during a merge, you can resolve conflicts either automatically or manually. If you choose to resolve the conflict manually, you can keep the source changes, keep the target changes, or resolve the conflict in the merge tool.

You might need to resolve conflicts when merging changes between branches, getting files into your workspace, or checking in new versions of files. There are three conflict types:
  • Version – The file has evolved along divergent paths. This could be the result of a file edit, rename, delete, or undelete operation.
  • File Name Collision – Two or more items are trying to occupy the same path.
  • Local Overwrite – Only occurs during a get operation, if you are trying to overwrite a local, editable file.

Most conflicts can be resolved automatically; version conflicts are the only conflict type that might result in a manual merge operation. Manual merge is most common in the following scenarios:
  • A file has been edited in both branches, with changes to the same lines of code.
  • A baseless merge is being conducted in which the branch file relationships are not known to TFS.

The merge tool shows you the details for each conflict and allows you to choose which change you want to keep in the final merged file. You can choose to keep the source change or the destination change, integrate both changes, or manually modify the final version by typing directly into the file.

After resolving every conflict in the file, save the final version as a pending change to be checked into the target branch.

Be careful when merging because it is easy to make mistakes that may result in build instability. After you have finished merging, compile the resulting source and run unit tests to test for major breaks.

Additional Resources

Last edited Jul 31, 2007 at 1:48 PM by prashantbansode, version 8


No comments yet.