Skip to content

Instantly share code, notes, and snippets.

@cweekly
Forked from tony4d/p4merge4git.md
Last active August 29, 2015 13:58
Show Gist options
  • Save cweekly/10173393 to your computer and use it in GitHub Desktop.
Save cweekly/10173393 to your computer and use it in GitHub Desktop.

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/\$LOCAL \$PWD/\$REMOTE \$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.
@cweekly
Copy link
Author

cweekly commented Feb 13, 2015

2015-02-13: the above worked well for me for a long time... till I started having problems with directories containing spaces. I should update the gist above, but have no time right now. I pasted a .gitconfig fix in a separate gist:
https://gist.github.com/cweekly/5757ef8f1e2c52c631b0

HTH :)

@galori
Copy link

galori commented Jun 15, 2015

Looking at the revision on your fork....why did you reverse LOCAL and REMOTE?

I did notice that during a merge, local is my branch and remote is the branch that I'm merging in. However during a rebase, the branch I'm rebasing against is considered LOCAL and my branch is REMOTE.

Is this the reason?

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