简体   繁体   English

恢复使用git clean -df删除的文件

[英]Restore files deleted with git clean -df

I was trying to clear my git after adding files from the wrong directory and ran the git clean -df function. 从错误的目录添加文件并运行git clean -df函数后,我试图清除git。 This resulted in all my user data being deleted. 这导致我的所有用户数据被删除。

I haven't done anything more in git after this, and I don't dare to turn of my PC at the moment. 此后,我在git中没有做任何其他事情,并且现在我不敢打开计算机。 However, I noticed that there is a .git folder which contains about 600MB of data. 但是,我注意到有一个.git文件夹,其中包含约600MB的数据。 Is it possible that y files are stored there and can be recovered? 是否有y个文件存储在那里并可以恢复?

I run Windows 10 and do not have any backup or restore points for the user data folder. 我运行Windows 10,并且没有用户数据文件夹的任何备份或还原点。

Any help would be greatly appreciated as I had som really important data stored. 任何帮助将不胜感激,因为我已存储了非常重要的数据。 Thank you 谢谢

There's no way to recover from this unless you had a backup or want to explore using undelete utilities. 除非您有备份或想使用撤消删除实用程序进行探索,否则无法从中恢复。 Git is not saving backups anywhere. Git不在任何地方保存备份。

Short answer and most probable there is not!! 简短的答案,最有可能没有!

Still some IDE's track and store locally this information see for example: Is it still possible to restore deleted untracked files in git? 还有一些IDE可以在本地跟踪和存储此信息,例如: 是否仍然可以在git中恢复已删除的未跟踪文件?

So depending on your IDE or text editor it still might be possible. 因此,仍然有可能取决于您的IDE或文本编辑器。

If you're using Eclipse, and you're only missing code or text, don't despair, not all may be lost. 如果您使用的是Eclipse,并且只缺少代码或文本,请不要绝望,不会丢失所有内容。 Go to: 去:

[WORKSPACE]/.metadata/.plugins/org.eclipse.core.resources/.history

Then use grep (*nix), FINDSTR (Windows) or a similiar tool to search for text snippets you know to have occurred in the deleted files. 然后使用grep (* nix), FINDSTR (Windows)或类似工具搜索您知道已删除文件中已出现的文本片段。 Eclipse keeps a lot of local history revisions around, so if you worked on these files recently, you will probably have a lot of matches. Eclipse保留了许多本地历史记录修订,因此,如果您最近使用这些文件,则可能会有很多匹配项。 Then you need to find most recent one of these, which can be a bit tricky. 然后,您需要找到其中的最新版本,这可能会有些棘手。

To give an example: After doing a quick git clean -d -fx to show this dangerous feature to a colleague, I was missing an untracked java code file, of which I knew it contained the String XrefCollector . 举个例子:在快速执行git clean -d -fx向同事展示此危险功能后,我丢失了一个未跟踪的Java代码文件,我知道该文件包含String XrefCollector I was able to find the last local history revision by doing this: 通过执行以下操作,我能够找到最近的本地历史记录修订:

find . -printf "%T@ %p\n" | sort -n | cut -d" " -f2 | xargs grep -l XrefCollector | tail -n1

Here, find prepends the date (epoch) to the files, sort sorts (numerically), cut removes the date again, and xargs passes the filenames on to grep , which searches for the desired string. 在这里, find在文件前加上日期(纪元),对文件sort排序(数字地sort ), cut再次删除日期, xargs将文件名传递给grep ,后者搜索所需的字符串。 Finally, tail only shows the last line of output. 最后, tail仅显示输出的最后一行。

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

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