Mercurial Remove History

There is no simple / recommended way of doing this directly to an existing repository.

You can however “convert” your mercurial repo to a new mercurial repo and choose a revision from where to include the history onwards via the convert.hg.startrev option

hg convert --config convert.hg.startrev=1234 <source-repository> <new-repository-name>

The new repo will contain everything from the original repo minus the history previous to the starting revision.

Caveat: The new repo will have completely new changeset IDs, i.e. it is in no way related to the original repo. After creating the new repo every developer has to clone the new repo and delete their clones from the original repo.

I used this to cleanup old repos used internally within our company – combined with the –filemap option to remove unwanted files too.

Leave a Comment