Examining a changeset in HG
Solution 1
Your question has two parts. First, how to get the metadata and diff for a changeset all at once:
hg log --patch --rev tip
You can shorten the options:
hg log -pr tip
The second part of the question is how to say "the parent changeset of X" without looking it up. For that you can use the parentrevspec extension Martin mentioned.
Once you enable the extension you can do:
hg log -pr tip^
You could add an alias to your ~/.hgrc
file if you don't want to retrain your fingers from git's command:
[alias]
show = log -pr
Then you could use:
hg show tip^
Solution 2
I think you want hg export cset
.
Solution 3
A similar command to "git show HEAD^" would be:
hg log -pr -2 # -1 (last commit), -2 - one before it, etc.
OR
hg exp tip^ # tip^ is similar to -r -2
or for instance if you want to look at the last 3 commits (with diff):
hg log -pr -3: # colon means start 3 commits behind and up to tip inclusive
A bit to late with the answer, but still. :)
UPDATE: apparently now HG supports git syntax as well:
hg exp tip^^^..tip
or
hg log -pr tip~4
Solution 4
If you just want to see the contents and differential of a commit, use this:
hg diff -c <the commit hash or bookmark name>
To see the commit you've checked out (HEAD in git), do this:
hg diff -c -1
If you want to see the commit before it (HEAD^ in git), do this:
hg diff -c -2
Simple.
Solution 5
You should also take a look at the parentrevspec extension to enable a more Git-like syntax for specifying revisions.
Comments
-
notnoop almost 2 years
How can I examine a changeset in mercurial without looking up its parent? In mercurial, what's the equivalent of
git show HEAD^
Git-show gives the changeset metadata and the diff as well.
-
Ry4an Brase almost 15 yearsWithout parentrevspec he could just do "-r -2" to get the changeset before tip, right?
-
tonfa almost 15 yearsIn general, for this case,
hg export
is preferred (it lists full commit message, etc.). -
Steve Losh almost 15 yearsPreferred by who? If you want the full commit message you can add
--verbose
/-v
to the log command.log
's output is much more human readable (the date and node/parent IDs are in a friendlier format) and it supports--color
, unlikeexport
. -
Cheetah over 11 years
hg help revsets
is your friend. You can use-r 'parents(rev)'
to get all the parents (multiple in the case of merging) or-r 'p1(rev)'
or-r 'p2(rev)'
for the first or second parent of a rev. -
Ibrahim Quraish about 6 yearsThis has the benefit that it takes "--stat" like git show does.
-
wchargin over 4 yearsThis is not an “exact equivalent”: unlike
git show
,hg log -pr
only shows the headline of the commit message, not the entire message. To show the entire message, one must also pass-v
, as inhg log -pvr REV
. -
Alex over 4 years@wchargin fair enough. Is the answer really bad enough for downvote? What about exp example?
-
wchargin over 4 yearsI’d be more than happy to remove the downvote if the answer is fixed to not say that they are “exactly equivalent” or “equivalent” when they’re not. :-)
-
wchargin over 4 yearsI had a commit whose message was originally one line long, and which I later reworded to add details. I found this answer and ran
hg log -pr -2
, and saw that the message was only one line. As this command was supposed to be equivalent togit show
, it followed that I must be on the wrong commit, so I spent some time trying to find out how that might have happened. (Did I accidentally rebase/evolve something?) In reality, I was never on the wrong commit. I didn’t downvote to “nitpick”; I downvoted because the fact that this answer was incorrect caused me confusion and lost me time. -
Alex over 4 yearsI still think it's nitpicking. I'm not even sure the
git show
was the same 6 years back. Anyway I've updated the answer to not use the wordequivalent
, to avoid any further confusion.