简体   繁体   English

用git取回已删除的文件

[英]getting back deleted files with git

If I create a new branch and then delete files, can I get them back by checking out a previous commit? 如果我创建一个新分支然后删除文件,可以通过签出先前的提交来找回它们吗?

for example: 例如:

git checkout -b get-rid-of-useless-files

rm useless.js

Oh no! 不好了!

git checkout

phew(?) phe(?)

是的,如果已签入文件并将其删除,则可以将其取回:

git checkout -- path/to/deleted/file

要添加到manojids答案中,如果您已经git rm /path/to/deleted/file您仍然可以git reset HEAD /path/to/deleted/file ,然后git checkout -- /path/to/deleted/file

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

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