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?

up vote 23 down vote accepted

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
  • I'm not using TortoiseHG, nor am I running Mercurial under Cygwin. I'm using the default command line Mercurial installer from mercurial.berkwood.com. Your solution worked, in the sense that I'm able to type 'hg winmerge <file>' to see the diff between it and the previous version, but 'hg diff <file>' still brings up the same (rather ugly) diff tool. Still, its better than nothing. – quanticle Aug 17 '09 at 15:31
  • I think this answer assumes that you will edit Mercurial.ini in the TortoiseHg directory (eg C:\Program Files\TortoiseHg). If you edit the one in the Mercurial directory (eg C:\Program Files\Mercurial) then this won't work (at least it didn't for me). – Ashley Davis Nov 16 '09 at 18:15
  • also c:\Program Files (x86)\WinMerge\WinMergeU.exe – Avram Jan 1 '13 at 16:01
  • Make sure you don't put quotes around the path to WinMerge in the config file, or it won't work. – Drealmer Mar 22 at 8:32

This is how it works for me -- pure mercurial command line other than tortoisehg

First, edit file (under a 64bit windows)

C:\Program Files (x86)\Mercurial\Mercurial.ini

[extensions]
; must uncomment this line
extdiff =

[extdiff]
; i'm using winmerge unicode version
cmd.winmerge = C:\Program Files (x86)\WinMerge\WinMergeU.exe
; it explains winmerge command line parameters here: http://winmerge.org/docs/manual/CommandLine.html
opts.winmerge = /r /e /x /u /wl

Then, you can use "hg winmerge ..." instead of "hg diff ..."

  • I find it useful to run winmerge in the background so I can look at changes while setting the commit message and also display stats on what files have change on the command line. To do this put a batch file in the mercurial directory that contains start /b hg winmerge<NEWLINE> hg diff --stat – danio Jun 18 '10 at 9:51

Well, the answers given earlier doesn't give me desired effects. They doesn't allow to make revisions diff and in place edit(I mean the same functionality which is available for TortoiseSVN from the box). To do that I've added additionally to mercurial.ini this section:

[merge-tools]
winmerge.regkey=Software\Thingamahoochie\WinMerge\
winmerge.regname=Executable
winmerge.priority=-10
winmerge.args=/e /x /wl /ub /dl other /dr local $other $local $output
winmerge.fixeol=True
winmerge.checkchanged=True
winmerge.gui=True
winmerge.diffargs=/r /e /x /ub /wl /dl '$plabel1' /dr '$clabel' $parent $child
winmerge.diff3args=
winmerge.dirdiff=True

This is taken from http://blog.stevehorn.cc/blog/easy-mercurial-visual-diff-between-two.html

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.