删除文件以后,如何通过git撤销删除的文件,不提交到远端代码库

检查状态,看看发生了什么:
$ git status
On branch master
Changed but not updated:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: app/controllers/application_controller.rb
no changes added to commit (use "git add" and/or "git commit -a")
可以看出,我们删除了一个文件。但是这个改动只发生在工作区(working tree)中,还未提交到仓库。这意
味着,我们可以使用checkout 命令,并指定-f 旗标,强制撤销这次改动:
$ git checkout -f
$ git status
# On branch master
nothing to commit (working directory clean)
$ ls app/controllers/
application_controller.rb concerns/
删除的目录和文件又回来了,ohlala!

posted on 2018-03-03 09:41  一只猪儿虫  阅读(243)  评论(0编辑  收藏  举报