How to locate and recover a deleted file

2019-03-22 22:12发布

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?

2条回答
啃猪蹄的小仙女
2楼-- · 2019-03-22 22:26

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"
查看更多
The star\"
3楼-- · 2019-03-22 22:29

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.

Edit: Incorporated Brian's comment about putting path_to_file in single quotes.

查看更多
登录 后发表回答