Git Diff with Beyond Compare

I have succeeded in getting git to start Beyond Compare 3 as a diff tool however, when I do a diff, the file I am comparing against is not being loaded. Only the latest version of the file is loaded and nothing else, so there is nothing in the right pane of Beyond Compare.

I am running git 1.6.3.1 with Cygwin with Beyond Compare 3. I have set up beyond compare as they suggest in the support part of their website with a script like such:

  • OSX Using Beyond Compare as git difftool
  • Compare and Edit Branches in Git with a Mergetool
  • Use BeyondCompare to see difference between files in GIT
  • git difftool to give directory compare?
  • How do I make Beyond Compare ignore certain differences while comparing versions of Delphi Form Files
  • How can I import a directory structure into SVN, keeping the file and folder modifed dates the same?

  • #!/bin/sh
    # diff is called by git with 7 parameters:
    # path old-file old-hex old-mode new-file new-hex new-mode
    "path_to_bc3_executable" "$2" "$5" | cat

    Has anyone else encountered this problem and know a solution to this?

    Edit:
    I have followed the suggestions by VonC but I am still having exactly the same problem as before. I am kinda new to Git so perhaps I am not using the diff correctly.

    For example, I am trying to see the diff on a file with a command like such:

    git diff main.css

    Beyond Compare will then open and only display my current main.css in the left pane, there is nothing in the right pane. I would like the see my current main.css in the left pane compared to the HEAD, basically what I have last committed.

    My git-diff-wrapper.sh looks like this:

    #!/bin/sh
    # diff is called by git with 7 parameters:
    # path old-file old-hex old-mode new-file new-hex new-mode
    "c:/Program Files/Beyond Compare 3/BCompare.exe" "$2" "$5" | cat

    My git config looks like this for Diff:

    [diff]
    external = c:/cygwin/bin/git-diff-wrapper.sh

  • maven-release-plugin deploy goal fails on project with folder at top level in git repository
  • web.config and app.config machine-specific settings in git
  • Git Bash (1.9.0) using Windows Explorer intergration crashes folder explorer
  • How to recover files from index
  • Move a file to a new folder, keeping Git history
  • PHPStorm display working branch name
  • 13 Solutions collect form web for “Git Diff with Beyond Compare”

    I don’t use extra wrapper .sh files. My environment is Windows XP, git 1.7.1 on cygwin, and Beyond Compare 3. Following is my .git/config file.

    [diff]
        tool = bc3
    [difftool]
        prompt = false
    [difftool "bc3"]
        #use cygpath to transform cygwin path $LOCAL (something like /tmp/U5VvP1_abc) to windows path, because bc3 is a windows software
        cmd = \"c:/program files/beyond compare 3/bcomp.exe\" "$(cygpath -w $LOCAL)" "$REMOTE"
    [merge]
        tool = bc3
    [mergetool]
        prompt = false
    [mergetool "bc3"]
        #trustExitCode = true
        cmd = \"c:/program files/beyond compare 3/bcomp.exe\" "$LOCAL" "$REMOTE" "$BASE" "$MERGED"
    

    Then, I use $ git difftool to compare and $ git mergetool to merge.

    About trustExitCode:
    For a custom merge command, specify whether the exit code of the merge command can be used to determine whether the merge was successful. If this is not set to true then the merge target file timestamp is checked and the merge assumed to have been successful if the file has been updated, otherwise the user is prompted to indicate the success of the merge.

    Thanks to @dahlbyk, the author of Posh-Git, for posting his config as a gist. It helped me resolve my configuration issue.

    [diff]
        tool = bc3
    [difftool]
        prompt = false
    [difftool "bc3"]
        cmd = \"c:/program files (x86)/beyond compare 3/bcomp.exe\" \"$LOCAL\" \"$REMOTE\"
    [merge]
        tool = bc3
    [mergetool]
        prompt = false
        keepBackup = false
    [mergetool "bc3"]
        cmd = \"c:/program files (x86)/beyond compare 3/bcomp.exe\" \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\"
        trustExitCode = true
    [alias]
        dt = difftool
        mt = mergetool
    

    Run these commands for Beyond Compare 2:

    git config --global diff.tool bc2
    git config --global difftool.bc2.cmd "\"c:/program files (x86)/beyond compare 2/bc2.exe\" \"$LOCAL\" \"$REMOTE\""
    git config --global difftool.prompt false
    

    Run these commands for Beyond Compare 3:

    git config --global diff.tool bc3
    git config --global difftool.bc3.cmd "\"c:/program files (x86)/beyond compare 3/bcomp.exe\" \"$LOCAL\" \"$REMOTE\""
    git config --global difftool.prompt false
    

    Then use git difftool

    Here is my config file. It took some wrestling but now it is working.
    I am using windows server, msysgit and beyond compare 3 (apparently an x86 version). Youll notice that I dont need to specify any arguments, and I use “path” instead of “cmd”.

    [user]
            name = PeteW
            email = petew@petew.com
    [diff]
            tool = bc3
    [difftool]
            prompt = false
    [difftool "bc3"]
            path = /c/Program Files (x86)/Beyond Compare 3/BComp.exe
    [merge]
            tool = bc3
    [mergetool]
            prompt = false
            keepBackup = false
    [mergetool "bc3"]
            path = /c/Program Files (x86)/Beyond Compare 3/BComp.exe
            trustExitCode = true
    [alias]
            dt = difftool
            mt = mergetool
    

    The Beyond Compare support page is a bit brief.

    Check my diff.external answer for more (regarding the exact syntax)

    Extract:

    $ git config --global diff.external <path_to_wrapper_script>
    

    at the command prompt, replacing with the path to “git-diff-wrapper.sh“, so your ~/.gitconfig contains

    -->8-(snip)--
    [diff]
        external = <path_to_wrapper_script>
    --8<-(snap)--
    

    Be sure to use the correct syntax to specify the paths to the wrapper script and diff tool, i.e. use forward slashed instead of backslashes. In my case, I have

    [diff]
        external = c:/Documents and Settings/sschuber/git-diff-wrapper.sh
    

    in .gitconfig and

    "d:/Program Files/Beyond Compare 3/BCompare.exe" "$2" "$5" | cat
    

    in the wrapper script.


    Note: you can also use git difftool.

    Official documentation worked for me

    it looks like BC3 only supports 3 way merge for PRO Edition.
    http://www.scootersoftware.com/moreinfo.php?zz=kb_editions

    Please notice you make a wrong path of $2.
    because you are under Cygwin but BC3 not, so you should specify a full path for it. such as “d:/cygwin$2”

    Please refer my git-diff-wrapper.sh here:

    $ cat ~/git-diff-wrapper.sh
    #!/bin/sh
    echo $2
    echo $5
    /cygdrive/c/Program\ Files\ \(x86\)/Beyond\ Compare\ 3/BCompare.exe "d:/programs/cygwin$2" "$5"
    

    Good luck.

    Run these commands for Beyond Compare 3(if the BCompare.exe path is different in your system, please replace it according to yours):

    git config --global diff.tool bc3
    git config --global difftool.bc3.cmd "\"c:/program files (x86)/beyond compare 3/BCompare.exe\" \"$LOCAL\" \"$REMOTE\""
    git config --global difftool.prompt false
    

    Then use git difftool

    For whatever reason, for me, the tmp file created by git diff was being deleted before it opened in beyond compare. I had to copy it out to another location first.

    cp -r $2 "/cygdrive/c/temp$2"
    cygstart /cygdrive/c/Program\ Files\ \(x86\)/Beyond\ Compare\ 3/BCompare.exe "C:/temp$2" "$5"
    

    The difference is in the exe being called: set it up to call bcomp.exe and it’ll work fine. Configure your environment to call bcompare.exe and you’ll end up with the side of the comparison taken from your revision system being empty.

    For MAC after doing lot of research it worked for me..!
    1. Install the beyond compare and this will be installed in below location

    /Applications/Beyond\ Compare.app/Contents/MacOS/bcomp

    Please follow these steps to make bc as diff/merge tool in git http://www.scootersoftware.com/support.php?zz=kb_mac

    Git Baby is a git and github fan, let's start git clone.