DEV Community

Kenneth Lum
Kenneth Lum

Posted on • Edited on

Super quick way to set up opendiff or Perforce p4merge as git diff

There is a super simple way to set up git to use opendiff or p4merge as the diff tool:

git config --global alias.diffy 'difftool -t opendiff -y'
git config --global alias.diffp 'difftool -t p4merge -y'
Enter fullscreen mode Exit fullscreen mode

after we do that, in the future, we can use

git diffy    # to use opendiff
git diffp    # to use p4merge
Enter fullscreen mode Exit fullscreen mode

Alternatively, Bash or Zsh aliases can be used:

alias gitd='git difftool -t opendiff -y'
alias gitd2='git difftool -t p4merge -y'
Enter fullscreen mode Exit fullscreen mode

To see what diff tools can be used:

git difftool --tool-help
Enter fullscreen mode Exit fullscreen mode

Details:

There are methods to set up git diff to use Xcode's FileMerge, or opendiff, or to use Perforce's p4merge. Usually the method is to set up an external shell script, and then set the diff.external to use that script.

The command git difftool, can readily perform the task without needing any external scripts. An extra advantage is, we can use opendiff or p4merge without altering diff.external

Note that when we use p4merge, we will need to add it to our path, which, for example, is /Applications/p4merge.app/Contents/MacOS on the Mac.

Top comments (0)