Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I repair a repository broken by hg unshelve?

I used hg shelve in a repository, where I had some unfinished changes because I needed to switch to a different head and perform unrelated changes.

Once my work on the other head was committed, I switched back to the head on which I had originally used hg shelve and ran a hg unshelve command. This was the result:

$ hg unshelve
unshelving change 'default'
adding changesets
adding manifests
adding file changes
added 1 changesets with 4 changes to 4 files (+1 heads)
abort: uncommitted changes
$ hg diff
warning: ignoring unknown working parent 893e15ecb5b4!
$ 

I did run hg head before and after the unshelve command and saw identical outputs. The commit 893e15ecb5b4 never existed, I have no clue where Mercurial got it from.

In case it is of any relevance, I am running Mercurial version 2.8.2 on Ubuntu 14.04.

How can I get my repository back in a working state, and how can I get my shelved changes back?

like image 834
kasperd Avatar asked May 13 '15 11:05

kasperd


1 Answers

The following steps solved the problems for me:

  1. Use hg debugsetparents to replace the corrupted parent revision number 893e15ecb5b4 with the correct one I had updated to before using unshelve
  2. Because the above had left me in a state where Mercurial had forgotten all local changes, I had to use hg manifest | tr '\n' '\0' | xargs -0 touch to get it to notice any local changes again.
  3. The shelved changes could be recovered using patch -p1 < .hg/shelved/default.patch, which in my case did exactly what hg unshelve should have done for me in the first place.
like image 96
kasperd Avatar answered Sep 28 '22 07:09

kasperd