0

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

$git fetch -v upstream

我得到:

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

有什么办法可以强制 git 刷新完全丢失的文件?

4

2 回答 2

1

git结帐

如果该文件存在于索引中,则只需将其签出:

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
于 2013-10-26T21:19:25.363 回答
0

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

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

现在做git checkout -- path/to/myfile把它拿回来。

于 2013-10-26T21:21:06.183 回答