Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial equivalent to git's HEAD~1

Tags:

git

mercurial

In git it's quite convenient to identify a commit relative to the latest commit in the repo with HEAD~1.

I have searched and cannot find an equivalent for this in mercurial. I find mercurials revision numbers rather annoying.

like image 769
Keyo Avatar asked Jun 09 '11 04:06

Keyo


2 Answers

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).

like image 194
tonfa Avatar answered Oct 09 '22 00:10

tonfa


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.

like image 32
rain Avatar answered Oct 09 '22 01:10

rain