Concatenating multiple changesets into one

(See also: EditingHistory, HisteditExtension (which provides an editor-driven UI for this), RebaseProject (section Collapsing)).

Problem

Suppose you want to concatenate the last k changesets of a repository

into a single, combined changeset

Solution (using hg only)

Execute the following steps:

1: hg -R oldrepo update S

2: hg -R oldrepo revert -r tip --all

3: hg -R oldrepo commit -m "Combine changesets S+1..S+k"

4: hg clone -r tip oldrepo newrepo

Alternative Solution (using mq)

Integrate the changesets you want to concatenate in a patch queue (verify you don't have pending patches there using hg qseries).
1: hg qimport -r S:tip

Pop all the patches but the first.
2: hg qgoto qbase

"Fold" unapplied patches, i.e. concatenate changesets.
3: hg qfold $(hg qunapp)
This has the big advantage over the previous method that the commit messages will also be concatenated (separated by the * * * string). You can see the message using hg qhead and edit it using hg qrefresh -e.

Reintegrate the folded patch in the repository.
4: hg qfinish qbase
tip is now the concatenation of former changesets S:tip. There's no extra branch left, therefore no additional cleanup to do.


CategoryTipsAndTricks