Implementing 'git show' in Mercurial

Posted on in Software

One of my frequently used git commands is 'git show <rev>'. As in, "show me what the heck this guy did here." Unfortunately, Mercurial doesn't have the same command, but it's easy enough to implement it using an alias in your .hgrc.

The command you would run from the command line to get the output is: hg log --patch --rev <rev>. All, you need to do is drop this into the [alias] stanza of your .hgrc and you'll have the hg show command.

Below I have cleverly used my new 'hg show' command to show you the changes I made to my .hgrc in order to get the new alias working.

Ullr:Slaptijack scott$ hg show e67d5afb42a5
changeset:   274:e67d5afb42a5
tag:         tip
user:        "Scott Hebert"
date:        Sun Oct 25 09:51:24 2015 -0500
summary:     add show alias like 'git show'

diff -r 0fd0c0faf10c -r e67d5afb42a5 Slaptijack/hgrc
--- a/Slaptijack/hgrc Sun Oct 25 09:49:15 2015 -0500
+++ b/Slaptijack/hgrc Sun Oct 25 09:51:24 2015 -0500
@@ -3,3 +3,6 @@

 [extensions]
 color =
+
+[alias]
+show = log --patch --rev

UPDATE: A buddy of mine pointed out another way to implement this alias is to replace log --patch --rev with diff -c in the snippet above. In my testing, both options seem to work perfectly well. The alias that uses log gives you the changeset metadata in addition to the diff, so that might be only thing that plays into your adoption of one over the other.

I use Git in my daily work, but prefer Mercurial for personal projects.

Slaptijack's Koding Kraken