Visualizing the changes you have in your working directory before committing is critical to sound use and value from source control. git difftool is a convenient command to use when working with git to walk through the unstaged files in your working directory with changes to see what is different. When working with Mercurial, you can do pretty much the same thing with just a little bit of setup.
My preference for a tool to use for viewing changes in source control is Winmerge. As such, this post will walk through setting up Mercurial to easily view what has changed in different changesets or (more importantly for most day-to-day operations), between the tip changeset and what is in your working directory using Winmerge.
Using Git, I always set up Winmerge as the application that responds to
This handy command, when configured as I like it, cycles through all the unstaged changes in your working directory (or the staged changed with the –cached parameter) and present a visual diff in your tool of choice, file by file. Look for an upcoming post on how I like to set up my git environment.
With Mercurial, something similar can be accomplished pretty easily. There are two methods I typically use to view my changes before committing or to compare changesets. The first is to use TortoiseHg. The commit dialog is pretty nice. It presents everything dirty in your working directory with the opportunity to view differences right in the dialog or via Ctrl+D, you can pop open your configured visual diff tool (Winmerge for me) to compare your working directory copy of the file with your repository. This works pretty nicely. I have only one complaint about it. It’s painful to select a file from the list to view the diff. TortoiseHg doesn’t have a keyboard shortcut for moving focus to the list of changed files. The options (of which I am aware) are to use the mouse (to which I am religiously opposed) or to go through a sequence of 10ish keystrokes. Both of these are undesirable.
There is another option for inspecting differences that is close to what you get with
A good description of how to set up can be found here. He did a pretty good job of giving you what you need to use this. I prefer, though, to use “difftool” as my command, rather than Winmerge to have a little more consistency with git and have to think less when moving back and forth between them. He also has a lot of extra parameters that aren’t necessary (the “incantations”).
What I landed on having in my mercurial.ini (among other stuff) is this:
cmd.difftool = C:\Program Files (x86)\WinMerge\WinMergeU.exe
opts.difftool = /e /x /ub /wl
This results in the capability of doing some work in my working directory and then issuing:
to open Winmerge showing all the dirty changes in my working directory.
I can also look at the changes to a specific file with something like:
hg difftool .hgignore
In addition, I can compare my working directory with any changeset in the repository with the –r switch:
hg difftool –r SomeBranch
hg difftool –r SomeTag
hg difftool –r 3f72f49aa3301a93c1382415577f6ff7fd3cadc9
(where this is a hash representing a changeset)
hg difftool –r 10
(where 10 is a number representing a changeset)
Hopefully this will make your life and your interaction with source control easier.