簡體   English   中英

從本地存儲庫中刪除文件/文件夾后,如何從遠程git存儲庫中獲取文件/文件夾?

[英]How to get files/folders from a remote git repository after we delete them from our local repository?

我從本地存儲庫中刪除了幾個文件夾和文件,我剛剛選擇它們並刪除了它們。 (包括“ images”,“ config” .. etc等文件夾以及一些由我完成但不再需要的文件)

我嘗試了git pull upstream mastergit fetch upstream master以將那些文件和文件夾返回到我的本地存儲庫。

我所做的基本上就像

  1. 我從git獲得了一個存儲庫並將其放置在本地
  2. 我在本地對某些文件和文件夾進行了一些更改
  3. 我希望某些文件具有較舊的版本(第一步之后的版本)
  4. 我以為刪除文件並找回它們,並再次從git中獲得新副本(使用上述命令,很遺憾它們無法正常工作)
  5. 但是我可以創建一個新的本地存儲庫,並具有原始存儲庫的克隆。 但這工作太多了,然后我將丟失對其余文件所做的更改。

*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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM