Question

I'm trying to use git's new (as of git 1.7.11) directory diff command with Beyond Compare 3 as the difftool, but the temporary files are not being created.

For example:

git difftool --dir-diff <branch1> <branch2>

Beyond Compare opens a directory comparison with the correct directories and changed files listed.

However, when I click on any of the files I get the following error:

Unable to load C:\Users\<username>\AppData\Local\Temp\git-difftool.yG8V5\left\<path to some file>: The system cannot find the path specified

So, I check to see if the C:\Users\<username>\AppData\Local\Temp\git-difftool.yG8V5 directory exists and it doesn't.

Beyond Compare 3 works fine as the difftool for non-directory diffs and merges.

I'm using git for Windows (msysgit) 1.8.0.

Here are the relevant .gitconfig settings:

# External Visual Diff/Merge Tool
[diff]
    tool = bc3

[difftool "bc3"]
    path = "C:/Program Files (x86)/Beyond Compare 3/BComp.exe"

[merge]
    tool = bc3

[mergetool "bc3"]
    keepTemporaries = false
    trustExitCode = true
    keepBackup = false
    path = "C:/Program Files (x86)/Beyond Compare 3/BComp.exe"
Was it helpful?

Solution

There is a solution described here. Basically, if you modify your .gitconfig to use BCompare.exe instead of BComp.exe, the console session will remain open until the Beyond Compare window is closed.

Modify your .gitconfig settings to read:

# External Visual Diff/Merge Tool
[diff]
    tool = bc3

[difftool "bc3"]
    path = "C:/Program Files (x86)/Beyond Compare 3/BCompare.exe"

OTHER TIPS

Answer from Scott Wegner is have small drawback - if you try to run 2 compares simultaneously, second will not work. This is because BCompare.exe do not run second application instance and so, close started process too early.

Sadly, BCompare.exe does not understand /solo command line option, so I write small bat file in Beyond Compare 3 installation directory:

C:\Program Files (x86)\Beyond Compare 3\BCompD.bat

start /wait "" "%~dp0/bcomp.exe" %* /solo

and use it as tool

[difftool "bc3dir"]
    path = C:/Program Files (x86)/Beyond Compare 3/bcompd.bat
    cmd = \"C:/Program Files (x86)/Beyond Compare 3/bcompd.bat\" \"$LOCAL\" \"$REMOTE\"

I do not use this as default diff tol, so I name it bc3dir and use like next:

git difftool --dir-diff --tool=bc3dir 760be6d47d35b42a6a2409636b40a5521361e72f^ 760be6d47d35b42a6a2409636b40a5521361e72f

I tried @ScottWegner's answer, but it only works when Beyond Compare is not already running. I found the solution with the help of @SergeyAzarkevich 's answer. This is what I did in my .gitconfig

[diff]
    tool = bc3
[difftool]
    prompt = false
[difftool "bc3"]
    cmd = \"c:/program files (x86)/beyond compare 3/bcompare.exe\" -solo \"$LOCAL\" \"$REMOTE\"

Notice the -solo. This causes Beyond Compare to spawn a new instance of the program.

On windows, we should be using the /solo option, but since git difftool command, spawns sh.exe to process its command-line, the /solo option was getting incorrectly interpreted as a path. So I have to use it as -solo

With this option, I run start git difftool --dir-diff, so this will free up my command prompt, and a new prompt will continue waiting for the new instance of Beyond Compare to exit. This will also make sure that the temp files/folders created by git will continue to live till the diff tool exits.

Note that you have another case where git difftool --dir-diff might misbehave.

"git difftool --dir-diff" had a minor regression when started from a subdirectory, which has been fixed with Git 2.12 (Q1 2017).

See commit 853e10c (07 Dec 2016) by David Aguilar (davvid).
(Merged by Junio C Hamano -- gitster -- in commit afe0e2a, 19 Dec 2016)

difftool: fix dir-diff index creation when in a subdirectory

9ec26e7 (difftool: fix argument handling in subdirs, 2016-07-18, Git 2.9.3) corrected how path arguments are handled in a subdirectory, but it introduced a regression in how entries outside of the subdirectory are handled by dir-diff.

When preparing the right-side of the diff we only include the changed paths in the temporary area.
The left side of the diff is constructed from a temporary index that is built from the same set of changed files, but it was being constructed from within the subdirectory.
This is a problem because the indexed paths are toplevel-relative, and thus they were not getting added to the index.

Teach difftool to chdir to the toplevel of the repository before preparing its temporary indexes.
This ensures that all of the toplevel-relative paths are valid.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top