git recover deleted file where no commit was made after the delete

I deleted some files.

I did NOT commit yet.

I want to reset my workspace to recover the files.

I did a git checkout . .

But the deleted files are still missing.

And git status shows:

# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   deleted:    cc.properties
#   deleted:    store/README
#   deleted:    store/cc.properties
#

Why doesn't git checkout . reset the workspace to HEAD ?


The output tells you what you need to do. git reset HEAD cc.properties etc.

This will unstage the rm operation. After that, running a git status again will tell you that you need to do a git checkout -- cc.properties to get the file back.

Update: I have this in my config file

$ git config alias.unstage
reset HEAD

which I usually use to unstage stuff.


You've staged the deletion so you need to do:

git checkout HEAD cc.properties store/README store/cc.properties

git checkout . only checks out from the index where the deletion has already been staged.


只要做git checkout path/to/file-I-want-to-bring-back.txt

链接地址: http://www.djcxy.com/p/18938.html

上一篇: Git:如何在项目提交历史记录中找到已删除的文件?

下一篇: git恢复删除后没有提交的删除文件