Configuring a diff-tool for Git on Windows

22,241

Solution 1

In your command prompt, try: git config --global diff.tool p4diff

That worked for me, using a config file set up as you had described:

[diff]  
    tool = p4merge  
[difftool "p4diff"]  
    external = '"C:/Program Files/Perforce/p4merge.exe" "$LOCAL" "$REMOTE"'

Running git difftool opened p4merge as expected.

Ref: How do I view 'git diff' output with a visual diff program?

Solution 2

I'm on WIndows 7 using MSysGit v1.8.4.

For me, the only solution was to add p4merge to the system path variable (reboot needed afterwards). Having done this, i conf'd it like this:

git config --global diff.tool p4merge
git config --global difftool.p4merge.cmd 'p4merge.exe $LOCAL $REMOTE'
git config --global difftool.prompt false

git config --global merge.tool p4merge
git config --global mergetool.p4merge.cmd 'p4merge.exe $BASE $LOCAL $REMOTE $MERGED'
git config --global mergetool.prompt false
git config --global mergetool.trustExitCode false
git config --global mergetool.keepBackup false

I recommend you stick to "git config" instead of editing the conf manually because hyphens etc sometimes are different between these methods.

Solution 3

Dan Limerick has an excellent short tutorial on setting up Perforce's p4merge on Windows:

http://danlimerick.wordpress.com/2011/06/19/git-for-window-tip-use-p4merge-as-mergetool/

Tested with Git 1.9.4 and p4merge 2014.1 on Windows 7.

Solution 4

I personally like meld better from other open source tools for just diff,

Expanding @wengeezhang answer, here is the step to configure Meld as difftool.

  1. Add Meld.exe path("C:\Program Files (x86)\Meld") to environment path
  2. Fire up windows command prompt
  3. git config --global diff.tool meld
  4. git config --global difftool.meld.cmd "meld \"$LOCAL\" \"$REMOTE\""

Bonus tip: Go to Git repo's root directory and fire up following command to see all diff side by side

git difftool --dir-diff ./

Solution 5

  1. git config --global diff.tool p4merge
  2. git config --global difftool.p4merge.cmd "p4merge \"$LOCAL\" \"$REMOTE\""
  3. add p4merge.exe path("C:\Program Files\Perforce\p4merge.exe") to environment path

ps:

  • in step 2,you've to add \"$LOCAL\" \"$REMOTE\"(local diff remote),or p4merge won't know what to diff
Share:
22,241
Søren Pedersen
Author by

Søren Pedersen

iOS developer at Schibsted

Updated on August 01, 2022

Comments

  • Søren Pedersen
    Søren Pedersen almost 2 years

    Since git diff in powershell mostly results in a unreadable amount of whitespace or strange characters, I installed Perforce P4Merge, to handle merging and diff.

    However, I can't make git diff open the p4merge application to view the diff in. So far my .gitconfig looks like this:

    [diff]
        tool = p4diff
    
    [difftool "p4diff"]
        external = 'C:/PROGRA~1/Perforce/p4merge.exe "$LOCAL" "$REMOTE"'
        prompt = false
    
    [merge]
        keepBackup = false
        tool = p4merge
    
    [mergetool "p4merge"]
        cmd = "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
        path = 'C:/PROGRA~1/Perforce/p4merge.exe'
        prompt = false
        keepBackup = false
        keepTemporaries = false
        trustExitCode = false
    

    The paths are correct. But alas, git still attempts to present the diff in Powershell, when using git diff.

    So what's the trick to make this work?

  • leo
    leo almost 11 years
    shouldn't it be tool = p4diff? That's also what you get when you enter the command git config --global diff.tool p4diff
  • Nicholas Petersen
    Nicholas Petersen over 4 years
    i just got a bunch of errors when it tries to launch Meld ?
  • Sunil Shahu
    Sunil Shahu over 4 years
    @NicholasPetersen What kind of errors? An error excerpt will put more light on what is the issue.