Concatenating multiple changesets into one changeset

(See also [:EditingHistory])

Suppose you have a [:Repository:repository] with a number of [:ChangeSet:changesets] which you want to combine into a single changeset.

This can be done as follows using only the basic operations of Mercurial, namely [:Clone:clone], [:Push:push], and [:Pull:pull].

For simplicity, let us assume that the repository in question has a single [:Head:head], and you want to combine the last k [:Revision:revisions] into a single revision.

For concreteness, let us call the base revision R, and the ending revision R+k.

Let us furthermore assume the repository has no [:LocalModifications:local modifications].

The strategy is to take advantage of Mercurial's support for repositories with more than one head. What we do is create a [:Branch:branch] whose root revision is R and which consists of just one changeset (actually it can be multiple changesets, the principle is the same, but for simplicity let us assume one).

The procedure is as follows:

1: hg update R

2: hg revert -r tip --all

3: hg ci -m "Combined changesets between R and R+k"

4: hg clone -r tip oldrepo newrepo


CategoryTipsAndTricks