Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
538 views
in Technique[技术] by (71.8m points)

git - git恢复删除的文件,删除后未提交任何内容(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 .

(我做了一个git checkout .)

.

(。)

But the deleted files are still missing.

(但是删除的文件仍然丢失。)

And git status shows:

(并且git status显示:)

# 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 .

(为什么不git checkout .)

reset the workspace to HEAD ?

(将工作区重置为HEAD ?)

  ask by Homan translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The output tells you what you need to do.

(输出告诉您您需要做什么。)

git reset HEAD cc.properties etc.

(git reset HEAD cc.properties等)

This will unstage the rm operation.

(这将取消rm操作的阶段。)

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.

(之后,再次运行git status将告诉您您需要执行git checkout -- cc.properties来取回文件。)

Update: I have this in my config file

(更新:我的配置文件中有这个)

$ git config alias.unstage
reset HEAD

which I usually use to unstage stuff.

(我通常用它来撤消工作。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...