In an earlier post, I discussed using and configuring WinMerge as a compare tool in Team System. Here I discuss using SourceGear's DiffMerge as a custom merge tool.
It all started recently when I had a tricky merge to do in Team System, and I realized that I wanted a bit of their changes and a bit of mine—all from the same block of changes. The problem is that the default merge tool in Team System renders the text change blocks as huge buttons—given this, it's not possible to select a chunk of text from one of them. (Trying to select the text simply clicks the button that is displaying the text.) In addition, the default tool does not display differences within a line—instead, it only shows which lines have differences. This can be very annoying if you are doing a merge and there's a very long line that is highlighted as being different, as it knows which characters are different, but it won't show the specific differences.
Given this, I backed myself out of the tricky merge, and installed the latest version of Sourcegear's DiffMerge. From some preliminary research, it seems to be the best free, three-way merge tool.
Things I really like about DiffMerge include:
- You can select text from any of the panes and patch it together in the merge result window as necessary
- It displays differences within a line, which can be a huge time-saver!
- It does true three-way merges (it uses the common ancestor of a file to determine what it can merge automatically)
- It is completely free for commercial or personal usage
The only thing that I don't really like about it is that it doesn't have the super-cool monitor-wide diff pane that WinMerge has—given this, I still use WinMerge as my compare tool, and I use DiffMerge as my merge tool. However, I can certainly understand this, as merging is quite different than comparing, and it wouldn't really make sense to have the wide pane at the bottom for merging.
Here's a screenshot of DiffMerge with some silly sample code:
This is the merge view. The center file is always the ancestor—the file that existed before any of the current edits started. Note the highlighting of changes within lines. Also notice the tabs at the bottom—they change the middle file display from the original ancestor and the merge result, which can be quite useful.
You can simply select text from any window and paste it into the Merge Result window, as well as directly editing the text in the Merge Result window.
One trick with this tool is that the auto-merge is called "merge to center"; it's the toolbar button on the far right that shows two green arrows pointing into the middle. This is the three-way merge—it uses the information about the common ancestor to figure out which changes it should keep and which it should not. (Without a common ancestor, it's impossible for the tool to tell what it should do, which is to keep everybody's changes as long as they don't collide.) If the tool detects conflicting changes to the same text block, the auto-merge will not do anything with the conflicts. It will display a dialog like this in the sample case above where the namespace is a conflict, because two different people changed it from the base (ancestor) file:
Here's what the merge result looks like after auto-merging (note that the "merge to center" button is now grayed out):
And here's the reference view showing the original ancestor file (bottom tab selection):
Tip: The documentation suggests that, if you are going to use the auto-merge, you should do it before you do any manual merging, so that the auto-merge doesn't reverse or modify what you've already done. In addition, you can only use the auto-merge once—after that, the button is disabled.
Configuration of DiffMerge for Team System Merges
Once again, the web page with all the installation details for custom compare and merge tools is James Manning's blog post. Here is a walk-through for configuring DiffMerge as the merge tool.
First, in Visual Studio, click Tools, then Options. The options dialog appears—click the Source Control node, and then the Visual Studio Team Foundation Server subnode:
Click the Configure User Tools... button and the following dialog appears:
This list will be empty if you have the default tools configured. Here I have it already configured for WinMerge for the compare operation, but nothing for merge. Click Add... to add a new non-default tool. Here's the dialog when it first opens:
Enter the following data:
- .* for the extension (this will use the merge tool for all extensions)
- Merge for the operation
- Browse to the DiffMerge.exe file in C:\Program Files\SourceGear\DiffMerge for the Command
- Enter the following DiffMerge command line arguments from James Manning's incredibly useful post: /title1=%6 /title2=%8 /title3=%7 /result=%4 %1 %3 %2
It should look something like this when you are done:
Next, click OK. You should now see your merge tool in the tool list:
Click OK, and then OK again to save the settings, and you should be all set!
Thanks to SourceGear for making this tool available to everyone for free! I think it's a winner!
PS: If you try using a custom compare/merge tool and don't like it, it's super easy to undo this process. To go back to the default tool, simply return to the Configure User Tools dialog, select the desired tool under file extensions, and click Remove. (If nothing is configured here, then it uses the default tools.)