[英]How to get files/folders from a remote git repository after we delete them from our local repository?
我從本地存儲庫中刪除了幾個文件夾和文件,我剛剛選擇它們並刪除了它們。 (包括“ images”,“ config” .. etc等文件夾以及一些由我完成但不再需要的文件)
我嘗試了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.*
那么,有什么辦法可以讓我安全地恢復那些已刪除的文件並擁有這些新副本。
注意:我沒有提交刪除
Frist使用git status
查看您刪除了哪些文件,然后使用git checkout filename_or_dir_name
來恢復它們。
例如:
# 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
,恢復的文件是“新的”,其他則不是。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.