tags:

views:

714

answers:

3

Accidentally, and by using a GUI as opposed to CLI, i removed every file in a project in Mercurial.

I recovered with Revert ok and lost some work, which as i have time machine i could easily get back. But is there a way of un-removing/un-deleteing such files? Trawled through the manual and googled but cannot see anything. Any plugins?

I am probably answering my own question here but the files were gone from the directory and were not in the trash to recover so i am assuming Remove is irrevocable?

p.s. i know that 'hg forget' or 'hg remove -Af' will remove without deleting from the directory but my question is to do with the error i made as opposed to cooly thinking the action through.

A: 

You can undo the last commit on a repo with hg rollback. There's only one level of rollback available, so if you did the remove with more than one commit, this won't completely undo your change. This only works on your local repository, so if you've pushed you won't be able to undo it in the remote repo.

ataylor
No this doesn't work. I am using a Mac with Mercurial Distributed SCM (version 1.4.1+20091201). I set up a repository, committed all, Removed and then committed again but this only brings back a list of the files marked as R(emoved) but does not actually bring the files back. If i mark the files as R(emoved) and Rollback before committing nothing happens either.
PurplePilot
After you've done the hg rollback, your repo will be rolled back, but your current working directory will still have your changes. Just tell hg to do a clean update to the rolled back revision, now on the tip: hg up -C.
ataylor
`hg rollback` will not recover removed file because the deletion of the file is not part of the commit transaction.
mrucci
That's right. If you're looking to get at edits that were not committed before the remove, they are lost.
ataylor
+1  A: 

Quote from comment:

I set up a repository, committed all, Removed and then committed again

If this is the case then you just need to update the working directory to the previous revision:

$ hg update -C -r-2

Note the negative revision number. If the files you deleted aren't in the previous revision, you can find them by using:

$ hg log -v
mrucci
A: 

First, use hg grep to find the deleted file you wish to recover. The output of this command will show you the last revision for which the file was present, and the path to the deleted file. Second, run hg revert -r <revision number> <path to deleted file> The deleted file will now be in your working copy, ready to be committed back into head.

BungleFeet