简体   繁体   English

如何恢复克隆期间删除的文件git

[英]How to restore files git deleted during clone

After working on something for a while, I thought I should put it in a git repo. 在工作了一段时间后,我认为应该将其放入git repo中。 Using gitlab, I created a new repo and cloned it from the command line onto my Windows 7 machine. 使用gitlab,我创建了一个新的存储库,并将其从命令行克隆到Windows 7计算机上。 This created a folder with a .git folder in it. 这创建了一个带有.git文件夹的文件夹。 I then copied all the files I'd been working on into the folder. 然后,我将所有正在处理的文件复制到该文件夹​​中。 I then noticed that the command line where I had cloned the repo was asking for a password. 然后,我注意到克隆仓库的命令行要求输入密码。 I entered the wrong password a couple of times and stupidly hit ctrl+c. 我几次输入了错误的密码,然后愚蠢地按了ctrl + c。 Next thing I knew, the folder with all my files was gone. 我知道的下一件事,是我所有文件的文件夹都消失了。 It is not in the recycle bin. 它不在回收站中。 Is there any way to restore these files? 有什么办法可以还原这些文件?

Unfortunately, they are lost and git won't help you here. 不幸的是,他们迷路了,git在这里没有帮助。 You should rely on file recovery tools to help you recover the files (long, hard and boring process) if you can afford to rewrite your code from scratch. 如果您有能力从头开始重写代码,则应依靠文件恢复工具来帮助您恢复文件(漫长,艰苦而无聊的过程)。

Buy I could tell you what you did wrong with git and what you should have done to never have been in such a situation... 求购我可以告诉您git做错了什么,以及在从未遇到过这种情况时应该做些什么...

You should have done : 1. Create a local repository in your project directory with 'git init'. 您应该完成以下操作:1.使用'git init'在项目目录中创建本地存储库。 2. Do as much development and commits as you want (but at least one...). 2.根据需要进行尽可能多的开发和提交(但至少要进行一次...)。 You are now protected against file deletion! 现在,您可以防止文件被删除! 3. Once you think it worth to be shared, like you do, create the repository in gitlab. 3.一旦您认为值得共享,就像您一样,在gitlab中创建存储库。 4. Add the gitlab repository as a remote in your local repository. 4.将gitlab存储库添加为本地存储库中的远程目录。 5. Push the history to the gitlab central repository. 5.将历史记录推送到gitlab中央存储库。

Like that, you should have avoided all the risky action you did and your work is secured at all times. 这样,您应该避免进行所有冒险的操作,并且始终确保工作安全。

Standard methods for removed file restoration apply: 适用于已删除文件还原的标准方法:

  1. Suspend any user operations on the HD (don't create/copy/remove files). 暂停HD上的所有用户操作(不要创建/复制/删除文件)。 This will increase your chances when trying to restore. 这将增加您尝试还原时的机会。

  2. Check if you have the file copies/originals in other folders. 检查其他文件夹中是否有文件副本/原始文件。 You mentioned that you had copied them previously into git folder. 您提到您之前已将它们复制到git文件夹中。 May you have them in the original directory? 您可以将它们放在原始目录中吗?

  3. Do you have any backup system running (like Crashplan, etc) ? 您是否正在运行任何备份系统(例如Crashplan等)? Check if you have a backup of the files 检查是否有文件备份

  4. If nothing of the previous helped proceed to the undelete operation - use dedicated utilities like this one for ex.: http://www.ntfsundelete.com 如果以前没有任何帮助继续进行删除操作,请使用像这样的专用实用程序作为示例: http : //www.ntfsundelete.com

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

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