如何在Git中取消删除文件? [英] How to undelete files in 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屋!