情景描述:
不小心在本地删除了一个文件,想从仓库 git pull 或者 git fetch 拉下来,事实告诉我么这样行不通;
解决办法:
1、首先用 git status 查看工作区变化
$ git status
On branch master
Your branch is up to date with 'origin/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: test.txt
no changes added to commit (use "git add" and/or "git commit -a")
工作区告诉我么,test.txt 文件已经删除,可以进行 add commit 操作…………
2、真正解决问题开始
执行:
$ git reset HEAD test.txt
Unstaged changes after reset:
D test.txt
再执行:
git checkout test.txt
现在看一下 text.txt 果然回来了,下面试测试效果