Mercurial equivalent to git's HEAD~1

The revset feature of Mercurial is extremely powerful (and much less arcane than git revision specification syntax): see hg help revsets (or online at: http://www.selenic.com/mercurial/hg.1.html#specifying-revision-sets).

See here for a list of predicates (I don't know why they aren't displayed in the online doc): http://hg.intevation.org/mercurial/crew/file/e597ef52a7c2/mercurial/revset.py#l811

In your case that would be: p1(tip).


The correct answer is .^ or .~1.

tip points to the latest revision that entered the repository, not the current revision you're on. Any answers that include tip in them are incorrect.

Mercurial's revset syntax is specified in more detail here: https://www.mercurial-scm.org/repo/hg/help/revsets

x^n: The nth parent of x, n == 0, 1, or 2. For n == 0, x; for n == 1, the first parent of each changeset in x; for n == 2, the second parent of changeset in x.

x~n: The nth first ancestor of x; "x~0" is x; "x~3" is "x^^^". For n < 0, the nth unambiguous descendant of x.

x^: Equivalent to "x^1", the first parent of each changeset in x.


There is a mercurial extension that adds git like commands.
Specific command is hg log -pr .^1.

For extra information, see examining a changeset in hg

Edit: Use .^1, not tip^1. As mentioned below, tip gives the most recent commit in the entire repo, which is possibly not what you want. The . is closer in meaning to git's HEAD. (See also: Specify dot as a revision in Mercurial)

Tags:

Git

Mercurial