34

The default diff tool of Visual Studio Code is nice, but I'd like to replace it with my beloved Beyond Compare.

It's easy to configure in Visual Studio 2017. It's also configured as the git difftool.

I assumed there should be an extension for Beyond Compare, but I couldn't find one. Also google only delivered results concerning the full VS IDE, but nothing to VSC.

Any suggestions?

Ash
  • 3,283
  • 6
  • 16
  • 20
  • I came here with the same question. I did find the [Compare Folders](https://marketplace.visualstudio.com/items?itemName=moshfeu.compare-folders) extension to be useful. – blaylockbk May 19 '22 at 18:30

5 Answers5

12

Try this extension:

GitDiffer - Visual Studio Marketplace

It works for me on Windows 10, here is my .gitconfig settings

[difftool "sourcetree"]
    cmd = 'C:/Program Files/Beyond Compare 4/BComp.exe' \"$LOCAL\" \"$REMOTE\"
[mergetool "sourcetree"]
    cmd = 'C:/Program Files/Beyond Compare 4/BComp.exe' \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\"
    trustExitCode = true
[merge]
    tool = sourcetree
[diff]
    guitool = sourcetree
abatishchev
  • 98,240
  • 88
  • 296
  • 433
allenyllee
  • 964
  • 1
  • 13
  • 16
  • git config --global diff.guitool "'C:/Program Files/Beyond Compare 4/BComp.exe' $LOCAL $REMOTE" does not work, it will ignore the $LOCAL and $REMOTE portions. Any idea of how the command need be written to set the values you specify? – prw56 Mar 15 '21 at 17:03
9

There is a better solution now, the "Compare Helper" extension: https://marketplace.visualstudio.com/items?itemName=keewek.compare-helper

Once installed and configured, you can select files or folders from the explorer and compare them via the context menu. Works like a charm, and configuration is trivial:

  "compareHelper.defaultExternalTools": {
    "folders": "bcompare",
    "images": "bcompare",
    "text": "bcompare"
  },
  "compareHelper.externalTools": [
    {
      "name": "bcompare",
      "path": "C:/Program Files/Beyond Compare 4/BCompare.exe",
      "compares": ["text", "folders", "images"]
    }
  ],

enter image description here

opus131
  • 1,976
  • 1
  • 11
  • 13
  • 3
    I could not get that extension to work. No matter what I put in the Compare(External) options are always grayed out. Kind of a bummer. – GeneralZod Feb 25 '22 at 00:08
  • 2
    Make sure that you have exactly two files selected in the VScode explorer. @killian – opus131 Feb 26 '22 at 17:35
  • `and configuration is trivial`... well, that piece of code obviously needs to go somewhere, but how exactly is that trivial? –  Aug 02 '22 at 19:27
  • 1
    @bbbbbbbbb the snippet goes into the VS Code settings file. I added a screenshot to my original reply. – opus131 Aug 05 '22 at 14:00
  • Thank you very much! What about the fact that the options in the `Compare` submenu are both disabled, always and mo matter what you (I) do? –  Aug 06 '22 at 15:16
  • @bbbbbbbbb As I answered above, as long as two files or folders are selected in the VS explorer, the options are not greyed out, at least for me. If that does not work for you then I'd suggest you raise the issue with the extension authors: https://github.com/keewek/vscode-compare-helper/issues – opus131 Aug 08 '22 at 09:13
  • 1
    But there is no such thing as "two files" in this context. There's a single file which has been modified, and I need to compare it to its previous version. This previous version is available via the source control service in my project, and obviously not on the VS explorer itself. So are you saying that your solution is not designated for source-control type of comparisons? –  Aug 08 '22 at 10:18
  • "So are you saying that your solution is not designated for source-control type of comparisons?" Yes, the scope of my solution was always to compare files and folders from the explorer, as you can see in my initial answer. – opus131 Aug 08 '22 at 10:41
  • It does not work with "select for compare" and "compare with selected". I wish it worked with that way of selecting 2 files too. But thanks for the extension. – vmiheer Dec 28 '22 at 16:39
4

I would file an issue/enhancement on Microsoft's Github @ the VSCode repo: https://github.com/Microsoft/vscode

Best case, it's doable and someone there can direct you pretty quick on how to accomplish it; worst case it's added as an enhancement request and added into Code itself in due time.

scrthq
  • 1,039
  • 11
  • 17
  • 1
    Thanks for the hint. I opened a feature request on github. – Ash Jun 14 '17 at 08:51
  • Until something better comes along for super tight Beyond Compare integration with VSCode, see this work-around: https://github.com/Microsoft/vscode/issues/28705#issuecomment-318562674 – Al Dass Aug 02 '17 at 04:41
2

I came here searching for a solution to use Beyond Compare from within the VS Code sidebar explorer, which is probably not exactly what the OP was after. However, maybe he or others might still find this useful:

There is an extension called "Windows Explorer Context Menu" which adds the option to show the native shell context menu for a selected file or folder in the VS Code explorer.

Once the extension is installed, you can right-click a file or folder, choose Context Menu - Selected and then the desired Beyond Compare operation from the native shell menu.

Unfortunately it does not recognise multiple selected files, so in order to compare two files or folders you have to do this twice, first Select left file/folder for Compare and then Compare (so tbh it's not really easier than just doing a Reveal in Explorer, but at least you can stay inside the VS Code context).

opus131
  • 1,976
  • 1
  • 11
  • 13
0

For VS Code on Mac OS

1. Install the VS Code Compare Helper Extension

2. Install Beyond Compare command line tools

Inside of Beyond Compare install the command line tools from the menu Install Beyond Compare Command Line Tools enter image description here

3. Add the following to your VSCode settings.json

"compareHelper.defaultExternalTools": {
    "folders": "bcompare",
    "images": "bcompare",
    "text": "bcompare"
},
"compareHelper.externalTools": [
    {
        "name": "bcompare",
        "path": "bcompare",
        "compares": [ "text", "folders", "images" ],
        "args": [
            "${FOLDER_ITEM_1}",
            "${FOLDER_ITEM_2}"
        ]
    }
],
Justin Ohms
  • 3,334
  • 31
  • 45
  • This worked well up until about May 2023, there must have been a VS code update. Now the context menu items are greyed out no matter how many files are selected. – Justin Ohms May 03 '23 at 22:07