I’ve found that the best way to deal with merging is to avoid it completely! Unfortunately that is rarely realistic. So, assuming you don’t want to take any radical measures to completely avoid merging in TFS, you should at least use the best tools available. My favorite merge tool is the freely available (and cross-platform) P4Merge.
Getting TFS to use P4Merge isn’t difficult but neither is it intuitive. For a merge operation P4Merge expects four files to exist:
- the original, base file
- file with conflicting change #1
- file with conflicting change #2
- final, merged file
Unfortunately TFS doesn’t create the merged file (#4) until after the merge tool is invoked. A simple batch script will solve the problem though. Save this as
@ECHO OFF COPY /Y NUL ""%4"" START /WAIT /D "C:\Program Files\Perforce\" p4merge.exe ""%1"" ""%2"" ""%3"" ""%4""
This script will create the merge file and invoke p4merge.exe.
Now you can configure TFS to use P4Merge by running this command from a Visual Studio command prompt:
tf diff /configure
That will bring up a dialog:
If an entry already exists for the Merge operation you can add it. Otherwise just modify the existing entry to point to the batch file we created:
Note that you must set the command to be your batch file, not the executable.
And that’s it! Next time TFS launches a merge tool, it will use P4Merge.