zobie's blog I create software, I like music, and I'm mildly(?) OCD.

30Apr/09

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:

  1. the original, base file
  2. file with conflicting change #1
  3. file with conflicting change #2
  4. 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

Visual Studio Command Prompt

That will bring up a dialog:

Configure User Tools

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:

Configure Tool

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.

Comments (3) Trackbacks (0)
  1. Great article, very original.

  2. 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!


Trackbacks are disabled.