Skip to content

Instantly share code, notes, and snippets.

@tony4d
Created August 24, 2012 19:00
Show Gist options
  • Save tony4d/3454372 to your computer and use it in GitHub Desktop.
Save tony4d/3454372 to your computer and use it in GitHub Desktop.
Setup p4merge as a visual diff and merge tool for git

Download and install p4merge

Setup p4merge as a visual mergetool

$ git config --global merge.tool p4mergetool
$ git config --global mergetool.p4mergetool.cmd \
"/Applications/p4merge.app/Contents/Resources/launchp4merge \$PWD/\$BASE \$PWD/\$REMOTE \$PWD/\$LOCAL \$PWD/\$MERGED"
$ git config --global mergetool.p4mergetool.trustExitCode false
$ git config --global mergetool.keepBackup false

Setup p4merge as a visual diff tool

$ git config --global diff.tool p4mergetool
$ git config --global difftool.p4mergetool.cmd \
"/Applications/p4merge.app/Contents/Resources/launchp4merge \$LOCAL \$REMOTE"

Using p4merge to resolve conflicts

When you run into a conflict when merging simply run:

$ git mergetool
  • You will be prompted to run "p4mergetool", hit enter and the visual merge editor will launch.
  • Using the merge tool you can resolve the conflict and then save the file.
  • After you exit the merge tool take a look back at your terminal. You will be asked if the merge was successful, choose yes if all is well or no if you need to start over.
  • This prompting is happening because the "trustExitCode" option is turned off. Personally I always like to be asked, but you can have git just trust the exit code from the merge tool.
@sebkraemer
Copy link

Works perfectly for me, @louim, thanks 👍

@umutseven92
Copy link

Thank you @louim, works like a charm 👍

@bogre
Copy link

bogre commented Jun 10, 2022

Does it prompts you for files when you run git diff-tool master..develop for example?
For me, it does and shouldn't be like that.

@pboling
Copy link

pboling commented Aug 21, 2023

There is a window that asks about the paths, but there is also a confirmation dialog that asks if it is OK for an Applescript to be run, and when you approve it to run the script (which you only have to do once), then the path window disappears and the merge opens as expected. I installed via homebrew.

@shivanraptor
Copy link

Still works perfectly in 2023. macOS Ventura

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