Skip to content

Instantly share code, notes, and snippets.

@samsalisbury
Last active June 22, 2022 19:30
Show Gist options
  • Star 72 You must be signed in to star a gist
  • Fork 17 You must be signed in to fork a gist
  • Save samsalisbury/5436108 to your computer and use it in GitHub Desktop.
Save samsalisbury/5436108 to your computer and use it in GitHub Desktop.
Git diff and merge with p4merge (OSX)
[merge]
keepBackup = false
tool = p4merge
[mergetool "p4merge"]
cmd = /Applications/p4merge.app/Contents/Resources/launchp4merge "\"$PWD/$BASE\"" "\"$PWD/$REMOTE\"" "\"$PWD/$LOCAL\"" "\"$PWD/$MERGED\""
keepTemporaries = false
trustExitCode = false
keepBackup = false
[diff]
tool = p4merge
[difftool "p4merge"]
cmd = /Applications/p4merge.app/Contents/Resources/launchp4merge "\"$REMOTE\"" "\"$LOCAL\""
@samsalisbury
Copy link
Author

  1. Install p4merge from perforce.com
  2. Put the following bits in your ~/.gitconfig, and then you can do $ git mergetool and $ git difftool to use p4merge
  3. Note that $ git diff will still just use the default inline diff viewer :)
    (tested with git version 1.8.2)

@daniloakamine
Copy link

Thanks for the helpful tip!

@King-Wizard
Copy link

Works like a charm, Thanks a lot.

Note: you could also disable the prompting for every file, adding these two lines below to ~/.gitconfig will do the trick:

[difftool]
        prompt = false

@ahammond
Copy link

I think you have remote and local mixed up. I swapped them and it looks more like what I'd expect in p4merge:

cmd = /Applications/p4merge.app/Contents/Resources/launchp4merge "\"$PWD/$BASE\"" "\"$PWD/$LOCAL\""  "\"$PWD/$REMOTE\"" "\"$PWD/$MERGED\""   

@andrescardona
Copy link

Thank you very much, works great!

@limboinf
Copy link

Thank a lot.

@samiraguiar
Copy link

Awesome, thanks!

@eric-holmberg
Copy link

very nice! thx

@jeff303
Copy link

jeff303 commented May 10, 2017

Anybody else getting a segmentation fault when attempting to run launchp4merge? Configured exactly the same as described above. Running simply p4merge (under /Contents/MacOS in the app package) seems to work fine. OS X 10.12.4, P4merge MACOSX1011X86_64/2017.1/1491634

@luckylooke
Copy link

Thank you @samsalisbury for sharing, and also thanks @kingWizard for useful flag. I am adding the usual path for global .gitconfig which is suprisingly ~/.gitconfig, maybe it will save a bit of googling :)

@mpern
Copy link

mpern commented Oct 6, 2017

@jeff303 googling for the same issue led me to your comment.

It looks like launchp4merge does not like running witout any arguments.
If I run launchp4merge to diff two files and just close the diff window, everything is fine. (even Cmd-Q works)

If I run launchp4merge without any arguments and also don't choose any files to diff after it launches, then a segfault happens.

@johny-gog
Copy link

It stopped working on MacOS Mojave for me :( Please help.

p4merge just opens without files chosen.

@UnreachableCode
Copy link

I am also getting the segmentation fault issue on Mojave 10.14.5.

@StanislavMayorov
Copy link

It still works with P4Merge/2019.2/1904275. Config should be updated like jeff303 said.

[merge]
  keepBackup = false
	tool = p4merge
[mergetool "p4merge"]
	cmd = /Applications/p4merge.app/Contents/MacOS/p4merge "\"$PWD/$BASE\"" "\"$PWD/$REMOTE\"" "\"$PWD/$LOCAL\"" "\"$PWD/$MERGED\""
	keepTemporaries = false
	trustExitCode = false
	keepBackup = false
[diff]
    tool = p4merge
[difftool "p4merge"]
	cmd = /Applications/p4merge.app/Contents/MacOS/p4merge "\"$REMOTE\"" "\"$LOCAL\""

@alexjjseppala
Copy link

I was finding that P4merge was leaving unwanted .orig files behind

Adding the following config (to [mergetool] on its own) stopped those files from being created

[mergetool]
        keepBackup = false

Reference: https://stackoverflow.com/questions/1251681/git-mergetool-generates-unwanted-orig-files

@factiondavid
Copy link

[merge]
  keepBackup = false
        tool = p4merge
[mergetool "p4merge"]
        cmd = /Applications/p4merge.app/Contents/MacOS/p4merge "\"$PWD/$BASE\"" "\"$PWD/$REMOTE\"" "\"$PWD/$LOCAL\"" "\"$PWD/$MERGED\""
        keepTemporaries = false
        trustExitCode = false
        keepBackup = false

This is not working on Monterey. Any one get it working?

@samsalisbury
Copy link
Author

What error are you seeing @factiondavid ? I no longer use p4merge, and I'm not yet upgraded to Monterey, but if you post more information about what you're seeing I'm sure someone might be able to offer more help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment