Skip to content

Instantly share code, notes, and snippets.

@IvanCl4udio
Last active January 7, 2024 02:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save IvanCl4udio/b606735bedcdcdea7cb7a9790d96ca74 to your computer and use it in GitHub Desktop.
Save IvanCl4udio/b606735bedcdcdea7cb7a9790d96ca74 to your computer and use it in GitHub Desktop.
How configure P4Merge as merge and diff tool on Linux

How configure P4Merge as merge and diff tool on Linux

If you like me use a Linux station to do your development and don't want to use the standard Git diff tool this Gist is for you.

Installation

  1. Download installation from Perforce Web Site

https://www.perforce.com/downloads/visual-merge-tool

Or download via command line:

$ curl https://cdist2.perforce.com/perforce/r19.1/bin.linux26x86_64/p4v.tgz -o p4v.tgz
  1. Unpack on a directory of your choice
$ sudo mkdir -p /opt/p4merge
$ sudo tar -zxvf p4v.tgz -C /opt/p4merge --strip-components=1
  1. Add the directory from p4merge binaries on you PATH variable changing the file ~/.profile:
$ vi ~/.profile
...
export PATH=$PATH:/opt/p4merge/bin
...
  1. Update your environment variables:
$ source ~/.profile 

Alternatively you can create a symbolic link inside a directory that alreadly setted on PATH variable of your system, for example:

$ sudo ln -s /opt/p4merge/bin/p4merge /usr/local/bin/p4merge

GIT Configuration

  1. Configure your git client to use P4Merge as your diff and merge tool
$ vi ~/.gitconfig
...
[merge]
    # Change to true if you wish to keep a backup of the files that was merged
    keepBackup = false;
    tool = p4merge
[mergetool]
    prompt = false
[mergetool "p4merge"]
    cmd = p4merge "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
    keepTemporaries = false
    trustExitCode = false
    keepBackup = false
[diff]
    tool = p4merge
[difftool]
    prompt = false
[difftool "p4merge"]
    cmd = p4merge "$LOCAL" "$REMOTE"
    keepTemporaries = false
    trustExitCode = false
    keepBackup = false
...
  1. To verify run
$ git difftool

Enjoy!

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