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

后端 未结 9 815
有刺的猬
有刺的猬 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:26

    An addition to the accepted answer - this is faster if you want to undo all removals in a commit. I deleted a large folder with a few hundred files in it and did hg addremove, which was not at all my intent, so had to undo all of those deletes.

    Using Find deleted files in Mercurial repository history, quickly? + xargs + tr, revert all revision -3 removals to the version from revision -4:

    hg log -r -3 --template "{rev}: {file_dels}\n" | tr ' ' '\n' | xargs hg revert -r -4 
    

    Note that this will fail if any of your files have spaces in the name; http://hgbook.red-bean.com/read/customizing-the-output-of-mercurial.html doesn't appear to have any templates where {file_dels} is split by \n at the moment.

提交回复
热议问题