Using P4Merge with Team Foundation Server
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 p4merge.bat.
@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.



August 7th, 2009 - 11:55
Great article, very original.
November 2nd, 2009 - 16:30
see also http://richardsbraindump.blogspot.com/2009/09/using-p4merge-with-visual-studio-2008.html
July 8th, 2010 - 13:17
Moving from a perforce environment to a TFS environment is a bit of an annoying shock when encountering the 3 way merge tool that TFS provides. Thank you for this. Removing developer friction is at the top of my list…and liking your tools is very important!