Search code examples
garbage-collectionmercurial

How to "GC" or "strip" hidden evolution changesets in Hg?


Hg has a new'ish Changeset Evolution feature and related Evolve extension.

This is pretty cool because many 'rewrite' operations are now moved into the DAG (like Git) - no more patch/linearization with MQ or shelving required! It also avoids painfully-slow-on-large-repository individual strips previously required for amend, rebase, histedit, etc.

However, after a period of time and many local rewrites there can accumulate a "significant number" of changesets that become hidden / tagged with obsolescence.

It is that time, and there are many changesets it would be nice to longer have (at all):

  • Is there a good/approved method to strip hidden/obsolesced changesets from the local Hg repository?

The 'comparable' operation in Git would be a GC which prunes orphaned commits.

I'd prefer not to re-clone the repository. In addition the hidden commits have (thankfully) not been pushed/published.


Solution

  • A simple way to safely get rid of obsolete changesets (well, as safe as hg strip can be) is to use the extinct() revset, i.e.:

    hg strip --hidden -r "extinct()"
    

    Extinct changesets are those that are obsolete and also only have obsolete descendants (i.e. no live changesets that still depend on them).

    Note that unless disk space becomes scarce, there should be no need to get rid of those changesets.