如何查找和恢复已删除的文件

Sto*_*oud 21 mercurial restore recover delete-file

在过去的某个阶段,我有一个"foo.txt",它在Mercurial源代码控制之下.但它现在已被删除.

当我不知道文件被删除的最后一个Mercurial修订版时,如何恢复该文件?

krt*_*tek 22

如果您知道文件的确切路径,则可以执行以下操作:

hg log -l 1 path/to/foo.txt
Run Code Online (Sandbox Code Playgroud)

这将显示foo.txt修改后的最后一个变更集,以便您可以从此修订中恢复该文件.

一旦你有了正确的修订版,你可以简单地做:

hg revert -r <my revision> path/to/foo.txt
hg commit -m "add the foo.txt file again"
Run Code Online (Sandbox Code Playgroud)

  • 我无法让你的日志命令工作.它不会显示删除发生的修订版本.我不得不做`hg log -l 1 --removed path/to/foo.txt`. (2认同)

sha*_*tor 9

使用revsets:

hg log -r "removes('path_to_file')"
Run Code Online (Sandbox Code Playgroud)

哪里path_to_file可以记录任何内容hg help patterns,包括精确路径,glob或正则表达式.

编辑:纳入Brian关于path_to_file单引号的评论.

  • 如果我将`path_to_file`括在单引号中,这对我有用. (2认同)