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

时间:2013-10-26 21:16:48

标签: git github

我在本地仓库中删除了一个文件pom.xml。我跑的时候

$git fetch -v upstream

我明白了:

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

有没有办法强制git刷新完全丢失的文件

2 个答案:

答案 0 :(得分:1)

git checkout

如果文件存在于索引中,则只需要检出:

git checkout deletedfile

示例:

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
$ 

更新文件以与遥控器中的版本完全匹配:

git checkout upstream/master deletedfile

答案 1 :(得分:0)

您的git status应指明您已删除的文件。

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

现在执行git checkout -- path/to/myfile以取回它。