Vlad
Vlad

Reputation: 315

git show equivalent in Mercurial

What would be the equivalent of git show in Mercurial ? I am mostly after the diff between given changeset and its parent, not necessarily the changeset metadata.

Ideally expressed as alias in hgrc.

Upvotes: 2

Views: 795

Answers (2)

torek
torek

Reputation: 488183

Edit: since hg show is now a core-provided extension, it's probably wise to pick another name. See also Reimer Behrends' answer and the comments there.


I have a tiny script I use. It is not terribly clever but it lets you use a git show <rev> or git show (to see HEAD / .) as hg show:

[alias]
show = !hg-show "$@"

where hg-show is:

#! /bin/sh

# hg-show - helper script for "hg show"

case $# in
0) $HG log -pv -r .;;
1) $HG log -pv -r "$1";;
*) $HG log -pv "$@";;
esac

It should be easy enough to put the entire script into the alias, if you prefer that. I had planned to make the script fancier someday, but have not been using Mercurial for several years now. (I first wrote the above script itself probably sometime around 2013.)

Upvotes: 0

Reimer Behrends
Reimer Behrends

Reputation: 8720

To see the diff for a commit, simply use hg diff -c REV. You can also specify the first and last revision by using -r twice, e.g. hg diff -r REV^ -r REV.

As an alias, just use:

[alias]
show = diff -c

(Note that show is already a Mercurial command, so you may want to pick a different name.)

Alternatively, hg log -p or hg export can also be used if you need to see the commit metadata as well, but hg diff -c allows you to use the regular diff options, e.g. to ignore whitespace.

For a revision range, you can use the :: revset operator. hg diff -r 'REV^::REV' works as well (see hg help revsets for more information on how to express non-trivial revision sets).

Upvotes: 4

Related Questions