我从本地存储库中删除了几个文件夹和文件,我刚刚选择了它们并将其删除。 (包括像'图像',' config' ..等文件夹以及一些由我完成修改但不再需要的文件)
我尝试git pull upstream master
和git fetch upstream master
将这些文件和文件夹恢复到我的本地存储库。
我所做的基本上就是,
*I have used SVN and there I can delete any file from the repo and when I get an update the file will be back. But I don't know how to do that with GIT.*
那么我有什么方法可以安全地恢复这些已删除的文件并拥有这些新副本。?
注意:我没有提交删除
答案 0 :(得分:1)
首次使用git status
查看您删除的文件,然后使用git checkout filename_or_dir_name
恢复这些文件。
e.g:
# atupal at atupal in /tmp/tmp [18:15:39]
$ git status .
On branch master
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: a
no changes added to commit (use "git add" and/or "git commit -a")
# atupal at atupal in /tmp/tmp [18:15:41]
$ ls
# atupal at atupal in /tmp/tmp [18:15:47]
$ git checkout .
# atupal at atupal in /tmp/tmp [18:15:51]
$ ls
a
# atupal at atupal in /tmp/tmp [18:15:55]
$
如果您使用git add file_name
暂存了已修改的文件,则在git-checkout
之后,恢复的文件为&#34;新鲜&#34;,其他不是。