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

后端 未结 9 750
有刺的猬
有刺的猬 2020-12-23 08:38

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 mach

相关标签:
9条回答
  • 2020-12-23 09:33

    The following worked for me.

    hg revert -r <Revision Number> <File Name>
    

    (Optional, to revert all files)

    hg revert -r <Revision Number> --all
    
    0 讨论(0)
  • 2020-12-23 09:40

    For Mercurial 1.6 and above

    If you know the name of the delete file you can find its revision easily with:

    hg log -r "removes('NAME.c')"
    

    This will give you the revision in witch a file called NAME.c (in the root) is deleted.

    Then you can revert the file to the previous revision with (like other answers):

    hg revert -r <revision number> <path to deleted file>
    

    You can use a file name pattern instead to adapt to what you know, for example you can use **/NAME.c to search in all directories. You can read about it in File Name Patters. And use this link to know about the new revset specifications.

    0 讨论(0)
  • 2020-12-23 09:41

    You can remove committed revisions using the hg strip command, which is provided by the mq (Mercurial Queues) extension. This should give you back your files.

    Make a backup before trying that out, because it will alter Mercurial's database of changesets.

    0 讨论(0)
提交回复
热议问题