Git中删除文件问题

学习了Git中删除文件

碰到了一下的问题

$ touch test.txt

$ git add test.txt

$ git commit -m "add test.txt"
On branch master
nothing to commit, working tree clean

$ git status
On branch master
nothing to commit, working tree clean

$ git rm test.txt
rm 'test.txt'

$ git checkout -- test.txt
error: pathspec 'test.txt' did not match any file(s) known to git

经过查询后知道,git rm 命令将Git中暂存区的test.txt文件删除了,所以这条命令没用,因为checkout命令只是将工作区恢复成暂存区的样子,而现在暂存区中没有了文件,自然提示找不到文件

要恢复文件先得将暂存区的test.txt恢复


$ git reset <filename>

恢复后再使用

$ git checkout -- test.txt

猜你喜欢

转载自www.cnblogs.com/naturals/p/12306022.html