How to Use WinMerge as the Diff tool for Mercurial

diff()mercurialwinmerge

I'm using the Mercurial distributed version control system, and I'm wondering how I can configure it to use WinMerge instead of its own internal diff tool. I've already got WinMerge as the merge tool, but I want Mercurial to use WinMerge when I type:

hg diff

Is there any way of doing that, or am I stuck with Mercurial's internal diff tool?

Best Answer

From the TortoiseHg FAQ:

Add these lines to your personal Mercurial.ini file

[extensions]
extdiff =

[extdiff]
cmd.winmerge = C:\Program Files\WinMerge\WinMergeU.exe
opts.winmerge = /e /x /u /wl

Now run the Global Settings tool. On the TortoiseHg tab, you should see winmerge available in the drop-down list for Visual Diff Command. Select winmerge, apply, then close.

This same approach can be used to add nearly any visual diff tool, but be aware that your diff tool must be able to support directory diffs if it is to be used by TortoiseHg, unless you are using release 0.8 or later.

Joel also provided a solution here in case you run Mercurial under Cygwin.

Explanation of WinMerge command line args here. Summary:

  • /e enables you to close WinMerge with a single Esc key press
  • /x closes WinMerge (after displaying an information dialog) when you start a comparison of identical files
  • /u prevents WinMerge from adding either path (left or right) to the Most Recently Used (MRU) list
  • /wl opens the left side as read-only
Related Question