我在本地仓库中删除了一个文件 pom.xml。当我跑
$git fetch -v upstream
我得到:
From <remote repo>:
= [up to date] master -> upstream/master
有什么办法可以强制 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
您git status
应该指出您已删除的文件。
Changes not staged for commit:
deleted: path/to/myfile
现在做git checkout -- path/to/myfile
把它拿回来。