How do I use a custom diff tool for specific file types in Visual Studio (with Git)?

Dion Misic 11 Reputation points
2021-03-24T03:59:27.977+00:00

Disclaimer: New to this forum, please retag if in the incorrect area of the site. I've also posted this question to StackOverflow for reference: https://stackoverflow.com/questions/66774427/how-do-i-use-a-custom-diff-tool-for-specific-file-types-in-visual-studio-with-g


I want to use a custom diff-tool in Visual Studio (2019) for specific file types, for example, I want to use the default visual studio diff tool for every other file type except for .xls and .xlsx extensions.

My use case is similar to https://stackoverflow.com/questions/20069976/setup-git-diff-for-special-file-types, however, I want to do it in Visual Studio (with git-scm).

~/.gitconfig

[diff "excel"]
    command = <path_to_my_diff_tool_for_xls>

~/.gitattributes

*.xls   diff=excel
*.xlsx  diff=excel

I have tried doing this at a repository-level and at a global-level with no success - Visual Studio just doesn't seem to pickup my diff-tool when I try to compare .xls files. It works successfully when I run git diff in the command-line - just not through the VS GUI.

Is there a reason that Visual Studio doesn't respect my diff-instructions in .gitattributes?


I found that when adding a local .gitattributes file through Visual Studio (Team Explorer > Settings > Repository Settings) it will generate a default, commented attribute file.

Within this file:

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs     diff=csharp

This wording (to me, atleast) implies that VS might not respect these types of entries in the .gitattribute files (besides through command prompt).


note: I am aware that I can override the diff tool, but I only want to use this tool on excel files and I can't find a way to do that like you could in TFS with the Configure User Tools popup.

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,193 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Tianyu Sun-MSFT 31,246 Reputation points Microsoft Vendor
    2021-03-24T13:36:58.367+00:00

    Hi @Dion Misic ,

    Welcome to Microsoft Q&A forum.

    I think you may need to do more, for example create an extension to let the custom diff tool work through VS GUI. As the “note” mentioned if you only change .gitattributes file it will only be used(work) by command line. So the workaround should be try to follow this reply: Visual Studio with Git for Windows which you mentioned “override the diff tool” or try to install and use the existing extensions which have the features that you need from Visual Studio Marketplace.

    Best Regards,
    Tianyu

    • If the answer is helpful, please click "Accept Answer" and upvote it.
      Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.