The bundle command creates data packages that can contain any number of commits and that can be applied to a working copy provided that the parent commit exists.  This is especially useful to back up branches that you don’t want to push yet, or before doing risky operations that might damage your data (e.g. a “successful” rebase with badly-merged data, happened to me).  Mercurial doesn’t seem to provide a reflog mechanism like git to allow you to undo anything more than the last commit.  (Please correct me if I’m wrong.)

Bundling

hg bundle bundle.hg COMMITS

This packs the selected commits into file bundle.hg.

COMMITS can be either:

  • -a    Packs the whole repo.
  • -b BRANCHNAME    Packs all commits that belong to branch BRANCHNAME.
  • –base REVNUMBER    Packs all children of commit with number REVNUMBER and their descendants.

Unbundling

$ hg unbundle BUNDLEFILE

What unbundling does

  • Unbundling simply adds to the working copy all bundled commits that don’t exist in the working copy.  Commits that exist in the working copy are left unchanged.
  • The parent commit of the bundled commits must be in the working copy.  If the parent commit has been stripped off, the bundle is useless.
  • If a bundled commit exists in the working copy but has been modified in the working copy since the bundle was packed, unbundling will create a new commit (or branch) that contains the bundled version.  You will not lose the modified version.