Manually unpacking a changeset bundle created by 'hg strip'

The strip command is useful for pruning abandoned lines of development from a repository. After removing a branch from revision graph the excised changes are backed up in a compressed bundle in case you want to undo the operation (with hg unbundle).

If you've done any history editing or rebasing that has rewritten the original anchor changeset of the pruned branch the bundle will no longer restore automatically into the revision graph. All is not lost however, as you can manually dig into the bundle to recover any useful code.

The bundles created by hg strip are BZip2 compressed files with the addition of a few custom header bytes: "HG10". To unpack the bundle just remove these first few bytes from the archive and uncompress with bzip2 as normal.

$ hg bundle -r tip tip.hg
searching for changes
5 changesets found

$ file tip.hg
tip.hg: Mercurial changeset bundle (bzip2 compressed)

$ python
Python 2.6.7 (r267:88850, Aug  3 2011, 11:33:52) 
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import bz2
>>> a = open('tip.hg').read()
>>> a[:10]
'HG10BZh91A'
>>> b = bz2.decompress(a[6:])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IOError: invalid data stream
>>> b = bz2.decompress("BZ" + a[6:])
>>> open("uncompressed", "w").write(b)
>>>

$ strings uncompressed | head
12a9abbe8b844df9fa8df826ea5fb80ed2deb045
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
1320687478 -3600
mercurial/context.py
 phases: improve context.phase()
9* force recompute of outdated cache
* handle nullrev case
)878c4add777f3499ba03c066ad3d27edfbd1fbdf
<1320671461 -3600
mercurial/localrepo.py

Thanks to mpm for this solution.


CategoryTipsAndTricks

ManuallyUnpackingStripBundle (last edited 2012-11-11 13:48:08 by abuehl)