Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I recover a removed file in Mercurial (if at all)?

Tags:

mercurial

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

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-remove/undelete 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 has to do with the error I made as opposed to cool thinking the action through.

like image 225
PurplePilot Avatar asked Feb 01 '10 08:02

PurplePilot


People also ask

How can I recover a deleted file or code?

First go to Recycle Bin of your local machine. Your VS code deleted files is there in Recycle Bin. So, Right click on deleted files and select-> Restore option then your deleted files will be automatically restored in your VS code.

How do I restore my last file?

Click the Computer icon on your desktop to open it up. Navigate to the folder that used to contain the file or folder, right-click it, and then click Restore previous versions. If the folder was at the top level of a drive, for example R:\, right-click the drive and then click Restore previous versions.


2 Answers

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.

like image 179
BungleFeet Avatar answered Sep 16 '22 18:09

BungleFeet


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 
like image 28
mrucci Avatar answered Sep 20 '22 18:09

mrucci