Rob Gilliam
Rob Gilliam

Reputation: 2950

How to use Visual Studio diff *only* for git diffs started from Visual Studio

I have configured my Git for Windows installation to use Beyond Compare (BC) for diffs and merges from the command line.

Unfortunately, when I'm working in Visual Studio 2022 and start a comparison for a file in the Git Changes tab, it starts BC to view the changes rather than just opening it in Visual Studio's built-in diff tool, which is not what I want.

If I go to the VS options I can select "Use Visual Studio" for diffs and merges, but this is changing my Git config so that, if I then do a git diff from the command line, it starts Visual Studio and loads the differences there for each file, rather than using Beyond Compare.

So, my question: [how] can I configure VS and/or Git to use VS diff when I'm in working in Visual Studio and my usual tool when I diff from the command line?

Upvotes: 2

Views: 543

Answers (1)

Piers Myers
Piers Myers

Reputation: 10899

You can use the git difftool --tool option.

If your .gitconfig files has the following lines:

[diff]
    tool = vsdiffmerge
[difftool]
    prompt = true
[difftool "bc"]
    cmd = \"C:\\Program Files (x86)\\Beyond Compare 4\\BCompare.exe\" \"$LOCAL\" \"$REMOTE\" -lro
    keepBackup = false
[difftool "vsdiffmerge"]
    cmd = \"C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer\\vsdiffmerge.exe\" \"$LOCAL\" \"$REMOTE\" //t
    keepBackup = false
[merge]
    tool = vsdiffmerge
[mergetool]
    prompt = true
[mergetool "bc"]
    cmd = \"C:\\Program Files (x86)\\Beyond Compare 4\\BCompare.exe\" \"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\"
    keepBackup = false
    trustExitCode = true
[mergetool "vsdiffmerge"]
    cmd = \"C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer\\vsdiffmerge.exe\" \"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\" //m
    keepBackup = false
    trustExitCode = true

Then Visual Studio 2022 will use the 'vsdiffmerge' setting and will use itself for diffs and merges.

From the command line you can use git difftool --dir-diff --tool=bc to use Beyond Compare. You could set up an alias for this if you wanted.

Upvotes: 2

Related Questions