The Mercurial Equivalent of `git show`

Published · Updated · Programming

git show <revision> is handy because it combines commit metadata and a patch. Mercurial does not use the same command name, but its composable commands make the equivalent clear: use hg log for the changeset description, hg diff -c for the patch, and hg export when the result needs to travel.

Inspect the changeset metadata

hg log -r REVISION

REVISION may be a local revision number, a changeset ID, a bookmark-related expression, or another valid Mercurial revision selector. The output gives the author, date, branch, description, and changeset identity. For a compact review-oriented view, use a template:

hg log -r REVISION --template '{node|short} {desc|firstline}\n'

Inspect the patch introduced by a changeset

hg diff -c REVISION

This shows the diff introduced by the selected changeset. Pair it with hg log -r REVISION when you need the practical equivalent of git show: what the commit claims to do and the actual code it changed.

Export a patch for handoff

hg export -r REVISION
hg export -r REVISION -o change.patch

hg export is best when the output needs to be a patch file or an email-friendly artifact. It is less pleasant for interactive inspection than using hg log and hg diff -c separately.

Be careful with a custom hg show command

An alias containing && is not a portable native Mercurial alias: native aliases expand to Mercurial commands, not an arbitrary shell sequence. Test the shell-alias form supported by the exact Mercurial version your team runs, or use a shell function where the dependency is explicit:

hgshow() {
  hg log -r "$1" && hg diff -c "$1"
}

Local revision numbers are convenient inside one clone but are not durable cross-clone identifiers. Prefer a changeset ID, tag, or bookmark when sharing an exact revision with another developer.

If short history output is what you miss, see custom Git and Mercurial log output. For a Git history decision that deserves deliberate handling in any VCS, read rebase versus merge.

More practical engineering notes

Slaptijack's Koding Kraken