Checkout the Last Public Revision with Mercurial

By  on  

I've always preferred git over Mercurial (hg) because the feature branch workflow makes organizing code and working off of master very easy. You don't get that with vanilla mercurial -- instead, commits can just sort of apply on top of each other, without much organization. Sometimes mercurial can feel a bit chaotic.

When working on Mozilla's mozilla-central repository (for your beloved Firefox!), I always start new commits off of the latest public commit. "public means it has been merged into mozilla-central, "draft" means it was created locally and is only on my machine.

Getting the last public revision ID required a bit of command line hackery and search so I found a better way to check out the last public revision:

hg checkout -r 'last(public())'

That command is a bit much to remember so I created an alias in my .bash_profile:

alias hgmaster='hg checkout -r “last(public())”’

As with every alias I create, whether a git alias or a bash alias, I wish I had created this sooner -- I'd have saved so much time!

Recent Features

  • By
    CSS vs. JS Animation: Which is Faster?

    How is it possible that JavaScript-based animation has secretly always been as fast — or faster — than CSS transitions? And, how is it possible that Adobe and Google consistently release media-rich mobile sites that rival the performance of native apps? This article serves as a point-by-point...

  • By
    9 Mind-Blowing Canvas Demos

    The <canvas> element has been a revelation for the visual experts among our ranks.  Canvas provides the means for incredible and efficient animations with the added bonus of no Flash; these developers can flash their awesome JavaScript skills instead.  Here are nine unbelievable canvas demos that...

Incredible Demos

  • By
    CSS Ellipsis Beginning of String

    I was incredibly happy when CSS text-overflow: ellipsis (married with fixed width and overflow: hidden was introduced to the CSS spec and browsers; the feature allowed us to stop trying to marry JavaScript width calculation with string width calculation and truncation.  CSS ellipsis was also very friendly to...

  • By
    Get Slick with MooTools Kwicks

    When I first saw MooTools graphical navigation, I was impressed. I thought it was a very simple yet creative way of using Flash. When I right-clicked and saw that it was JavaScript, I was floored. How could they achieve such...

Discussion

  1. Jeremy

    What do you mean you can’t use the feature branch workflow with Mercurial?

    • I guess branches are different with Mercurial, and that bookmarks don’t feel the same as branching off of master. Could just be me.

  2. glob

    It would be simpler/quicker to instead do:

    hg checkout -r 'last(public())'
  3. agentgt

    You can also use mercurials excellent revsetalias and alias support:

    [alias]
    master = update -r 'last(public())'
    
    [revsetalias]
    master = last(public())
    wip = (parents(not public()) or not public() or . or head()) and not closed()
    

    Now You can do

    hg update master
    

    or

    hg master
    

    I added the revset alias wip as well which shows the changes you haven’t yet pushed to master.

    Finally for lightweight branches I highly recommend the evolve extension and just making normal mercurial named branches that you only push to your local mutable (non publishing repository). So long as the branches are in draft you can delete them which will be the case if the repository is non publishing.

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!