Search code examples
mercurial

What are all of Mercurial's built in commit identifiers?


I'm looking for easy ways to move around to different commits, sometimes within a branch (and not necessarily from the latest commit). For example, I'd want a way to always get to the previous commit:

# move to commit before current commit
hg checkout -r ~.1

or move to the top of the branch

hg checkout tip

But I can't figure out things like how to move to the next commit (i.e. the one above the current commit, the negation of ~.1). hg seems to have built in ways of referencing these things (e.g. tip (latest commit), . (current commit), and .~N (N-th previous commit)), but are there any others?


Solution

    1. You have to re-read hg help revsets carefully and a) build (if needed) b) use these revsets in hg commands
    • If you want to use "~" notation, you have to use proper format of revset hg log -r ".~1" for immediate parent and remember "only 1-st parent is evaluated" (mergesets, f.e, have two parents)
    "x~n"
      The nth first ancestor of x
    
    • Top of named branch (branch head) isn't tip (tip - ltest commit in repo, can be in another branch), but branchname per se for hg up

    • With "x~n" revsets you can use negative numbers also: for n < 0, the nth unambiguous descendant of x.