How can I shrink a mercurial repository by removing old changesets?
Fundamentally, you can't. Mercurial has a hard and fast rule that a changeset can only exist in a repository if every one of its ancestor changesets also exists in that repository.
You can, however, create a new repository whose changesets correspond to a subset of the later changesets in another repository. They won't, however be the same changesets, because they'll have different hash nodeids, and any clones from the original repo won't work with the new one ("unrelated repositories").
You could try to create a new repo reflecting only some of newer changesets in another repo using a process like this:
hg -R /path/to/bigrepo export 10:tip > latestchanges.patch
hg init newsmallrepo
hg -R newsmallrepo import < latestchanges.patch
That would copy only the changesets numbered 10 and later into new changesets with different hashes in the new repository. It also won't work terribly well with merges.
See the convert
extension (included with Mercurial). A simple example is the following:
hg convert <src> <dest> --config convert.hg.startrev=<rev>
This will generate a new, unrelated repository that starts with the revision specified, dropping previous history. It will handle merges as well. All users will need to clone the new version of the repository, since changeset hashes will all change.
Enable the extension by adding the following to mercurial.ini
:
[extensions]
convert =
Run hg help convert
for options.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With