简体   繁体   English

用git意外删除了许多文件

[英]Accidental deletion of many files with git

I have accidentally deleted all stylesheet files of my website. 我不小心删除了我网站的所有样式表文件。

I'm using git but I don't push changes to any repo. 我正在使用git,但我不会将更改推送到任何存储库。 I just make commits on my development copy. 我只是在开发副本上提交。 So there is no repo to checkout from. 因此,没有回购的仓库。

So what I did was, I had a backup copy of my site (it's old and doesn't contain all the files) so manually copy pasted all the stylesheet files to my development copy. 所以我要做的是,我有一个网站的备份副本(它很旧,并且不包含所有文件),所以手动复制将所有样式表文件粘贴到我的开发副本中。

Is there any way to restore all that's gone? 有什么办法可以恢复所有的消失?

If you ever added and committed the files into your development Git repository you can go back in history via git checkout HASH . 如果您曾经将文件添加并提交到开发Git存储库中,则可以通过git checkout HASH返回历史记录。 This command will load all files with the state at the time of the HASH into the working directory. 此命令会将状态为HASH的所有文件加载到工作目录中。 You can also pick specific files at a specific state; 您还可以选择处于特定状态的特定文件。 try git checkout HASH -- filename . 尝试git checkout HASH -- filename If you accidently removed a commit that contains the relevant files you can lookup the total history of all Git actions via git reflog and kind of "revert" the state of your repository. 如果您不小心删除了包含相关文件的提交,则可以通过git reflog查找所有Git操作的总历史记录,并且可以“还原”存储库的状态。 In any cases make a copy of your repository before you start! 无论如何,请在开始之前复制您的存储库!

If you never added the files to the repository you can use one of the file system tools to undelete the files. 如果您从未将文件添加到存储库中,则可以使用文件系统工具之一来取消删除文件。 The application choice depends on the operating system you use. 应用程序的选择取决于您使用的操作系统。

您可以使用git checkout /path/to/file ,这将恢复文件在最后一次提交时的状态。

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

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