且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

git恢复删除后没有提交的删除文件

更新时间:2022-10-18 10:41:36

输出告诉你你需要做什么。 git reset HEAD cc.properties 等等。



这会取消rm操作。之后,再次运行 git status 会告诉您需要执行 git checkout - cc.properties 重新获得文件。

更新:
我在配置文件中有这个

  $ git config alias.unstage 
reset HEAD

我通常用它来取消东西。


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.