简体   繁体   English

如何刷新从远程git分支本地删除的文件

[英]How to refresh a file that was deleted locally from a remote git branch

I have deleted a file pom.xml in my local repo. 我已经在本地存储库中删除了文件pom.xml。 When I run 当我跑步

$git fetch -v upstream

I get: 我得到:

From <remote repo>:
 = [up to date]      master     -> upstream/master

Is there any way to force git to refresh files that are simply missing altogether ? 有没有办法强制git刷新完全丢失的文件?

git checkout git checkout

If the file exists in the index, it needs only to be checked out: 如果文件存在于索引中,则只需将其检出:

git checkout deletedfile

Example: 例:

cd my/repo
rm deletedfile 
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:    deletedfile
#
no changes added to commit (use "git add" and/or "git commit -a")
git checkout deletedfile
git status
# On branch master
nothing to commit, working directory clean
$ 

To update the file to exactly match the version in the remote: 要更新文件以使其与远程版本完全匹配:

git checkout upstream/master deletedfile

Your git status should indicate the file you have deleted. 您的git status应指示您已删除的文件。

Changes not staged for commit:
   deleted: path/to/myfile

Now do git checkout -- path/to/myfile to get it back. 现在执行git checkout -- path/to/myfile将其取回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM