Using Notepad++ diff tool for git

Viewed 1107

I would like to set the diff tool of Notepad++ to be used as the diff tool invoked when I do a git diff of files. The Google searches produce various things, with How do I use Notepad++ Compare as the diff tool in git bash/command line? often as the top search result.

That page's git config commands refer to a file that I do not have, namely Compare.exe, in the Notepad++ installation directories. When I do a compare from within Notepad++, it works fine. So is Compare.exe the result of installing some extra compare plugin? Notepad++ compare operations show up under the plugins menu there, so I thought I had the (a?) compare plugin installed.

1 Answers

Only way I could find is a workaround.

Compare Plugin does not include the external launcher compare.exe anymore. But git needs a mechanism like this to set N++ as a diff tool. With a bit of effort though it is still possible to do. Tested with Notepad++ v8.1.5(64bit) and Compare Plugin v2.0.1.

  1. Install Compare Plugin via Notepad's Plugins Admin option. (Update N++ when missing).

  2. Compile this project to get compare.exe file. Place it somewhere. I chose C:\Program Files\Notepad++\plugins\ComparePlugin\ComparePlugin\compare.exe.

(Note: Pre-compiled version found in downloads did not work for me. You need to have the latest build).

By now Notepad++ should start when running compare.exe fileA.txt fileB.txt.

Setting up git to use it.

git config --global diff.tool nppdiff
git config --global difftool.nppdiff.cmd "'C:\Program Files\Notepad++\plugins\ComparePlugin\ComparePlugin\compare.exe' \$LOCAL \$REMOTE"

Your .gitconfig file should now look like this.

[diff]
  tool = nppdiff
[difftool "nppdiff"]
  cmd = 'C:\\Program Files\\Notepad++\\plugins\\ComparePlugin\\ComparePlugin\\compare.exe' $LOCAL $REMOTE

Now git difftool -y will open Notepad++.

Related