Jay Taylor's notes

back to listing index

Using p4merge as a git mergetool | [ andy.mcintosh ]

[web search]
Original source (www.andymcintosh.com)
Tags: git p4merge merge mergetool www.andymcintosh.com
Clipped on: 2014-01-31

Using p4merge as a git mergetool

By andy.mcintosh | Published: April 4, 2009

So, don’t get me wrong, I hate Perforce. It actually makes my head hurt a little remembering my experience with it. The only saving grace was the Perforce merge tool, p4merge. There are number of different diff/merge tools that will work with git on OS X, but I’m not all that impressed with them — even the rather expensive Changes left me feeling underwhelmed.

Perforce Visual Merge Tool (shown on Windows)

After figuring out how to configure git to use Changes as its merging and diff tool, I set out on a mission (read: Google search) to figure out how to use p4merge instead. It turns out it’s pretty simple, but that all the pages with instructions on how to do it no longer exist.

Here are the steps to get it working:

Download and Install P4V

Download the free Perforce Visual Client dmg from here. Once it’s downloaded, copy p4merge from the disk image to your /Applications directory.

Write some simple shell scripts

p4merge*

Create a new text file in /usr/local/bin called p4merge and add the following lines:

#!/bin/sh
/Applications/p4merge.app/Contents/MacOS/p4merge $*

Make the script executable by entering this command:

chmod +x p4merge

p4diff*

Create a new text file in /usr/local/bin called p4diff and add the following lines:

#!/bin/sh
[ $# -eq 7 ] && /usr/local/bin/p4merge "$2" "$5"

Make the script executable by entering this command:

chmod +x p4diff

Configure Git to use the scripts

Open your git configuration file (probably ~/.gitconig) and add these lines:

[merge]
	keepBackup = false;
	tool = p4merge
[mergetool "p4merge"]
	cmd = p4merge "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
	keepTemporaries = false
	trustExitCode = false
	keepBackup = false
[diff]
	external = p4diff

Use it!

That’s it. Now when you run git-mergetool or git-diff the visual Perforce merge tool will launch with the files you want to merge or diff. Hope this helps!

This entry was posted in git. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.