恢复用git rm -rf删除的目录 [英] Recover directory removed with git rm -rf

查看:433
本文介绍了恢复用git rm -rf删除的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用git add将目录添加到本地git repo,然后意外地做了git rm -rf(之前未提交).有什么方法可以从该目录中恢复文件?

I added a directory to a local git repo using git add and then accidentally did git rm -rf (without committing before). Is there some way of recovering the files from this directory?

推荐答案

是的,

阅读此内容:如何撤消更改在Git中.

将文件添加到git后,它们开始被跟踪,并存储在.git文件夹下.

Once you add files to git they are started to be tracked and they are stored under the .git folder.

在它们只是被添加而从未提交的情况下,它们被称为dangling objects.这些对象可以恢复.

In they were just added and never commited they are refereed as dangling objects. Those object can be recovered.

首先我们必须找出它们

git fsck --full

一旦有了这些对象的列表,就需要查看它们并找出所需的对象.

Once you have the list of those object you need to view them and to find out which ones you need.

# Print out the content of the Object
git cat-file -p <SHA-1>

# If the object is a file you will simply see its content,
# Copy it and save it in a new file.



这篇关于恢复用git rm -rf删除的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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