在'git rm -rf'后恢复staged但未提交的文件 [英] Recover staged but not committed files after 'git rm -rf'

查看:368
本文介绍了在'git rm -rf'后恢复staged但未提交的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的本地机器上,我从文件夹中删除了文件。

  git init 
git add --all

然后我写了(不要问我,为什么!:))

  git rm -rf 

我还没有提交。现在我的项目中有空文件夹。在 .git 文件夹中包含53 MB的文件的 objects

如何恢复我的文件?我尝试过Drill Disc和Stellar等程序,但没有找到我的文件。我无法从GIT回滚。



如何恢复丢失的文件?

解决方案使用 git fsck 代替它,它是一个用于检索你曾经添加到git仓库中的文件的内置命令。

  git fsck --lost-found --unreachable 

命令处理后,检索到的文件将被放置在 .git / lost-found / other 中,文件名sha256散列。虽然原名仍然丢失,但内容将会恢复。




您可以在目录。

假设有一个 .git / objects / 2f / ae996f8f8f9298b41ba4fdbac3d62014f9579e 对象,你可以执行

  git cat-file -p 2fae996 


$ b

可以获取丢失文件的内容。



但是我很抱歉,我不知道重建您的目录或自动执行此操作。


On my local machine I removed files from folder.

git init
git add --all

then I wrote (don't ask me, why! :) )

git rm -rf

I don't commit, yet. Now I have empty folders in my project. In .git folder has objects with 53 Mb of files.

How can I recover my files? I've tried programs like Drill Disc and Stellar, but not found my files. And I can't rollback from GIT.

How can I recover the lost files?

解决方案

(update) Use git fsck instead, it is a builtin command for retrieving files you have once added to git repository.

git fsck --lost-found --unreachable

after the command processing, retrieved files will be placed at .git/lost-found/other, with file name of a sha256 hash. Although the original name is still lost, the content will be back.


You can find your files in your .git/objects directory.

Suppose there is a .git/objects/2f/ae996f8f8f9298b41ba4fdbac3d62014f9579e object, you can execute

git cat-file -p 2fae996

to get the content of your lost file.

But I'm sorry, I have no idea about reconstructing your directory or doing this automatically.

这篇关于在'git rm -rf'后恢复staged但未提交的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆