Can I set different difftools for git bash and visual studio 2019?

577 Views Asked by At

I use git bash, and Visual Studio 2019's built in git repository integration side-by-side for source control on the same repositories. By default, when I'm in Visual Studio and view changes to a file, the diff is shown within Visual Studio. When I run "git difftool" from the command line, the diffs are shown in a vim editor.

I want to change the git bash difftool from vim to vscode, so I changed my .gitconfig file like so:

[core]
    editor = code
[user]
    name = myname
    email = [email protected]
[diff]
    tool = vscode
[difftool "vscode"]
    cmd = code --wait --diff $LOCAL $REMOTE

Now running git difftools via command line opens the diff in a VSCode window. But this also causes Visual Studio to open the diff in a new VSCode window, rather than using it's built in diff viewer.

Is there a way to set up a default difftool for only git bash and not change the value for Visual Studio 2019?

1

There are 1 best solutions below

0
djohnson10 On

I believe I've found an acceptable answer:

I added 2 different difftool settings and then added "dt" as an alias that calls the one I want from the command line.

[core]
    editor = code
[user]
    name = myname
    email = [email protected]
[diff]
    tool = vscode
    guitool = vsdiffmerge
[difftool "vscode"]
    cmd = code --wait --diff $LOCAL $REMOTE
[difftool "vsdiffmerge"]
    cmd = \"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer\\vsdiffmerge.exe\" \"$LOCAL\" \"$REMOTE\" //t
    keepBackup = false
[alias]
dt = difftool --tool "vscode"

Solution is adapted from here: https://www.reddit.com/r/dotnet/comments/b9f9y6/visual_studio_ignoreoverride_git_diff_tool/ek4qa9f?utm_source=share&utm_medium=web2x&context=3