I love the command line. Very rarely do I ever not have a console window open. Consequently I tend to do all my source control activities from the command line. However I’m not a command line bigot. I know when the console has reached its limit and I have to resort to a more graphical tool. With Mercurial this hits hard when doing complicated diffs and of course the dreaded three way merge. Fortunately Mercurial has been configured out of the box to recognise my merge tool of choice so when Mercurial finds a conflict during a merge it can show me a GUI based tool that will help me get on with my work.
But what about the times when I want to review the changes that I’ve made? This is especially important when I’m about to push changes and inflict my work on other developers. It’s also a great opportunity to spot issues which may result in broken builds.
For small changes I still stick with the console and run:
$ hg diff
This gives me a fairly simple diff of my changes. I can make this even better
by enabling the color extension which will spruce up my command line
output by adding colour to a myriad of different commands, but importantly for
this case, diff. By marking insertions in green and deletions in red I can get
a very quick overview of the changes I have made. To enable this extension I
just add the following to my
However a basic diff is somewhat limited. It generally won’t take the filetype into consideration and a small change to a big line can be difficult to spot. Fortunately there are a number of great diff tools out there. The one I use is Beyond Compare 3 (you’ll need the Professional version if you want its excellent three way merge feature). It isn’t free, but for a tool I use every day I feel that it has been worth it many times over.
These instructions should work with any diff tool capable of understanding command line parameters and able to compare two folders.
To integrate our graphical diff tool with Mercurial we’ll turn to another extension, Extdiff. This extension helps you use a graphical diff tool to compare two different changesets (or a changeset with the current work in progress). Importantly it also makes sure that if you make any changes to the working copy they will be propagated back when you are done. So if your diff tool is good at moving changes from one file to another and editing files in place you can very easily clean up your changes. Enabling the extension is straightforward.
1 2 3
This has however only enabled the
extdiff command in Mercurial. If we want
to configure our diff tool of choice we have to make one final change.
1 2 3 4 5 6
Here I’ve added the
extdiff section and created a new command
will use Beyond Compare as my diff tool. So now to use Beyond Compare to view
my changes I just need to run the following:
$ hg vdiff
I can create as many of these commands as I like if I want to enable different diff tools. It is also possible to parse arguments to the diff tool. For instructions check out the Extdiff documentation page on the Mercurial wiki.