Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing changesets or shrinking a Mercurial repository

Tags:

mercurial

How can I shrink a mercurial repository by removing old changesets?

like image 480
John John Pichler Avatar asked Oct 19 '10 19:10

John John Pichler


2 Answers

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.

like image 59
Ry4an Brase Avatar answered Oct 05 '22 19:10

Ry4an Brase


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.

like image 40
Mark Tolonen Avatar answered Oct 05 '22 20:10

Mark Tolonen