简体   繁体   English

如何使用移动文件夹上的git恢复已删除的文件

[英]How to recover deleted files with git on moved folder

Several months ago I did a refactoring of paths to several java modules. 几个月前,我对几个Java模块进行了路径重构。 Now it seems that I have forgotten to move the src/test directory of one of the modules and instead deleted it... 现在看来,我已经忘记了移动其中一个模块的src / test目录,而是删除了它...

How can I recover all these deleted files? 如何恢复所有这些已删除的文件? Note that the path to the module where the files was located, is deleted, and I cannot remember the earlier path? 请注意,文件所在模块的路径已删除,我不记得以前的路径了吗?

As explained in this answer you can find the last commit where the file/folder was modified with this command: 如此答案中所述,您可以找到使用以下命令修改文件/文件夹的最后一次提交:

git log --full-history -- src/test

Once you find the commit where the file exists you can checkout it into your current working tree with as explained here : 找到文件所在的提交后,可以按照以下说明将其检出到当前工作树中:

git checkout <SHA>^ -- <path-to-file>

Note that <SHA> is the hash of the commit where the folder was deleted, so you make a checkout to the previous commit 请注意, <SHA>是删除文件夹的提交的哈希,因此您需要签出上一个提交

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM