Mercurial: Combining or Folding Changesets

No matter how much you know, there’s always something more to learn. I was listening to this episode of HerdingCode, and was going to respond to the misinformation about Mercurial. I read the comments, and learned the following.

Most Mercurial documentation recommends using MQ (Patch Queue) for folding changesets into a concise changeset. I won’t discuss how to do that here, but Google will point you in the right direction.

Another option which doesn’t directly involve MQ is the strip command. The strip command is part of the MQ extension, but you don’t have to know anything about MQ to use strip.

There’s a poorly documented parameter to strip, -k, that facilitates a type of folding process.

First, let’s cover what strip does normally. If I do

hg strip -r REV

hg will remove changeset REV and ALL descendants. It will create a backup bundle in the .hgstrip-backup repo with the hash of the changeset identified by REV. hg will also update the working directory to the parent changeset of REV.

Now if we do

hg strip -k -r REV

the result is a little different. The changesets are still stripped and backed up. An update to the parent of REV is still performed, BUT the working directory will contain uncommitted changes that reflect the culmination of all the changesets stripped. Now one can do a verification of the combine, and either commit with an appropriate message, or revert the change and import the backed up bundle.

It's only fair to share...
Share on FacebookGoogle+Tweet about this on TwitterShare on LinkedIn

Leave a Reply