Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to locate and recover a deleted file

Tags:

At some stage in the past I had a "foo.txt" which was under Mercurial source control. However it has now been deleted.

How can I recover the file when I don't know the last Mercurial revision in which the file was deleted?

like image 967
Stormcloud Avatar asked Mar 16 '12 09:03

Stormcloud


People also ask

Where to find a file I just deleted?

When you delete a file or folder, it goes into the Recycle bin, where you have a chance to restore it.

Can you still recover permanently deleted files?

When a file is permanently deleted from the Recycle Bin, it still resides on the hard drive until it's overwritten with new data. Therefore, a data recovery tool can be used to restore some or all of the data.


2 Answers

If you know the exact path for the file, you can do something like :

hg log -l 1 path/to/foo.txt 

This will show you the last changeset where foo.txt was modified, so you will be able to restore the file from this revision.

Once you have the right revision, you can simply do :

hg revert -r <my revision> path/to/foo.txt hg commit -m "add the foo.txt file again" 
like image 149
krtek Avatar answered Oct 11 '22 13:10

krtek


Using revsets:

hg log -r "removes('path_to_file')" 

Where path_to_file can be anything documented in hg help patterns, including an exact path, a glob or a regular expression.

like image 28
anton.burger Avatar answered Oct 11 '22 14:10

anton.burger