Last Updated: February 25, 2016
·
5.281K
· helmedeiros

git easy merging with merging tools!

Git Merging

Merging is Git's way of putting a forked history back together. The git merge command lets you take the independent lines of development created by git branch and integrate them into a single branch. The problem, for those that were a long time away from console, is how to check what was changed, and also get the correct merge when facing conflicts.

Resolving Conflicts

If the two branches you‘re trying to merge both changed the same part of the same file, Git won’t be able to figure out which version to use. When such a situation occurs, it stops right before the merge commit so that you can resolve the conflicts manually.

To help you with that you can use a merge tool called P4Merge. Check how to configure and use it.

Download and install p4merge

Download the P4Merge

  1. Visual Merge Tool from here: download page

  2. After that copy only the p4merge.app file into your /Applications/ directory.

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

8 Responses
Add your response

Great tip, thanks! Previously I had the following which worked, but it gave me all kinds of Mac OS X warnings in the Terminal:

[difftool]
    prompt = false
[difftool "p4merge"]
    external = "/Applications/p4merge.app/Contents/MacOS/p4merge" "$2" "$5" ||
[merge]
    tool = p4merge
[mergetool]
    prompt = false
    keepBackup = false
[mergetool "p4merge"]
    path = "/Applications/p4merge.app/Contents/MacOS/p4merge"
    trustExitCode = false

However, I still recommend adding prompt = false to [mergetool] and [difftool].

over 1 year ago ·

In my download of P4Merge, the app name is capitalized P4Merge.app. So I guess that because I just downloaded it, that's now the default..

over 1 year ago ·

@koen: Apple HFS volumes are case insensitive if not explicitly formatted otherwise.

over 1 year ago ·

I know, but why not use the actual filename when using capitalized directory names as well?

over 1 year ago ·

Or just use IntelliJ (or any other JetBrains IDE). It doesn't get any easier than that.

over 1 year ago ·

Hi! If your using atom editor the merge-conflicts package is really good!
https://atom.io/packages/merge-conflicts

over 1 year ago ·

I've had very good experiences with DiffMerge, nice thing about it that it has a client for Windows, Mac and Linux and it works well. The downside is that it's REALLY uggly

https://sourcegear.com/diffmerge/

over 1 year ago ·

I wrote tiny scripts to iron out Git + P4Merge integration: http://pempek.net/articles/2014/04/18/git-p4merge/

over 1 year ago ·