[英]How to get files/folders from a remote git repository after we delete them from our local repository?
I deleted several folders and files from the local repository I have just selected them and deleted them. 我从本地存储库中删除了几个文件夹和文件,我刚刚选择它们并删除了它们。 (including the folders like 'images' , 'config' ..etc and some files which have modifications done by me and not needed anymore)
(包括“ images”,“ config” .. etc等文件夹以及一些由我完成但不再需要的文件)
I tried git pull upstream master
and git fetch upstream master
to get those files and folders back to my local repository. 我尝试了
git pull upstream master
和git fetch upstream master
以将那些文件和文件夹返回到我的本地存储库。
What I did is basically like, 我所做的基本上就像
*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.*
So is there any way I can get those deleted files back safely and have those fresh copies.? 那么,有什么办法可以让我安全地恢复那些已删除的文件并拥有这些新副本。
Note : I did not commit the deletions 注意:我没有提交删除
Frist use git status
to look what files you have deleted and then use git checkout filename_or_dir_name
to resume them. Frist使用
git status
查看您删除了哪些文件,然后使用git checkout filename_or_dir_name
来恢复它们。
eg: 例如:
# 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]
$
If you have staged modified files by using git add file_name
, then after git-checkout
the resumed file is "fresh", other not. 如果您已经使用
git add file_name
了修改过的文件,那么在git-checkout
,恢复的文件是“新的”,其他则不是。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.