如何在Git中取消删除文件? [英] How to undelete files in Git?

查看:121
本文介绍了如何在Git中取消删除文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Git中的 rm 命令进行测试,我最终从驱动器中删除了所有文件。



导致这种情况发生的命令如下:

  git rm。 -r 

现在我的文件系统仅包含目录,而我以前添加到Git的所有文件



如何从Git存储库恢复所有文件?

解决方案

一般来说,如果它再次发生在你身上,但稍微有一点点变化不同的场景,例如只删除了几个文件,您仍可以使用相同的模式:

git checkout - < file_path> $ b

在这种情况下, git status 的输出也将帮助您提供可能的解决方案。 / p>

警告:对于这种特殊情况,您还可以运行 git reset --hard ,但上面的解决方案看起来有点干净。不要太习惯这个命令,因为你可能会意外地将你的修改擦掉。


Testing with the rm command in Git I ended up removing all my files from my drive.

The command that caused this to happen is the following:

git rm . -r

Now my file system contains only the directories while all the files that I have previously added to Git are missing.

How can I restore all the files from the Git repository?

解决方案

git checkout .

In general, if it happens again to you, but with a slightly different scenario like only deleted a few files, you can still use the same pattern:

git checkout -- <file_path>

In that case, the output of git status will also help you with providing possible solutions.

Warning: For this particular case, you can also run git reset --hard, but the solution above looks a bit cleaner. Do not get used to this command so easily because you might wipe your modifications away in the future accidentally.

这篇关于如何在Git中取消删除文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆