Fixing a failed integrity check in Mercurial?

Well, since the first damaged changeset is 170, you could clone your local repository to 169 and then pull from the source. That means only pulling 5 changesets.

hg clone -r 169 damagedrepo fixedrepo
cd fixedreop
hg verify

And then:

hg pull originalsource

As for manual recovery of repository corruption, this page expounds on that better than I can. See section 4:

I have found corruption once in a while before, and although the above documentation says it is usually from user error, my instances were on removable USB drives with empty working directories. Sometimes things just don't get written correctly or are interfered with somehow: it's not always user error. But I always have multiple copies I can reclone from so I've been able to get away with basic fixing.

If the simple fix of a partial local clone and pulling from the server doesn't fix it, you're down to 2 options after backing up your changes (if any) to a bundle or patches:

  • Manually hacking at Mercurial's files.
  • Doing a new full clone from the server. Usually the easier and faster of the two.

Beware: This method will change all hashes.


Actually there is another way to recover the repository when it is corrupted like this -

You can do a complete rebuild of the repository by using the convert extension. See Section 4.5 on https://www.mercurial-scm.org/wiki/RepositoryCorruption#Recovery_using_convert_extension

First enable the convert extension by adding the following to your ~/.hgrc file

[extensions]
convert=

Then convert the bad repo to create a fixed repo:

$ hg convert --config convert.hg.ignoreerrors=True REPO REPOFIX

This worked for me when I had the experience of suddenly finding that there were missing files in the manifests - "error 255".

Tags:

Mercurial