Managing Large Repos

Truncating History

Removing history from Mercurial is one way to reduce the size of the repository (the stuff in the .hg folder).

Unlike Git, Mercurial does not support a proper shallow copy. You can make a new repository based on a subset of the commits from an existing one, but these repos will not be considered related, the changeset IDs will change for each commit, and you cannot push or merge changes between the two.

The following command can be used to truncate history from a Mercurial repository.

 Where 1234  is the revision you want to start your new repository from, <source-repository> is the path to the existing repository, and <new-repository>  is the path to a folder where the new, truncated repository will be created in.

Anyone else using the existing repository will have to stop using it and clone the new, truncated one if they wish to continue development (this can be a big problem).

This does need the convert extension to be enabled (it comes shipped with Mercurial), which can be done by adding the following line under [extensions] in your mercurial.ini file.

 

Posted: January 12th, 2015 at 4:42 pm
Last Updated on: June 21st, 2016 at 4:12 pm