git删除了所有内容,如何恢复文件和文件夹 [英] git deleted everything, how to recover files and folders

查看:557
本文介绍了git删除了所有内容,如何恢复文件和文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次使用git,我想将一个现有的项目导入到github中,并且一切都被删除了。搜索答案后,我认为git删除后,git拉文件,我试图恢复文件和文件夹,但我找不到如何做到这一点。



我做了下一个:

  jesus @ jesus-K52F :〜/ Escritorio / Django / Ujixy $ git init 
在/home/jesus/Escritorio/Django/Ujixy/.git/
中初始化的空Git存储库jesus @ jesus-K52F:〜/ Escritorio / Django / Ujixy $ git add。
jesus @ jesus-K52F:〜/ Escritorio / Django / Ujixy $ git status
#分支主

#初始提交

#要提交的更改:
#(使用git rm --cached< file> ...来取消)

#新文件:Catalogoapp / __ init__.py
#新文件:Catalogoapp / models.py
#新文件:Catalogoapp / tests.py
#新文件:Catalogoapp / views.py
#新文件:Messageapp / __ init__.py
#新文件:Messageapp / models.py
#新文件:Messageapp / tests.py
#新文件:Messageapp / views.py
#新文件:Ujixyapp / __ init__。 py
[...]

jesus @ jesus-K52F:〜/ Escritorio / Django / Ujixy $ git push origin master
fatal:'origin'似乎不是一个git仓库
fatal:远程终端意外挂起
jesus @ jesus-K52F:〜/ Escritorio / Django / Ujixy $ git add *
jesus @ jesus-K52F:〜/ Escritorio / Django / Ujixy $ git status
#分支大师

#初始提交

#对b的更改e提交:
#(使用git rm --cached< file> ...来取消存储)

#新文件:Catalogoapp / __ init__.py
#新文件:Catalogoapp / models.py
#新文件:Catalogoapp / tests.py
#新文件:Catalogoapp / views.py
#新文件:Messageapp / __ init__.py
#新文件:Messageapp / models.py
#新文件:Messageapp / tests.py
#新文件:Messageapp / views.py
#新文件:Ujixyapp / __ init__.py
[...]
jesus @ jesus-K52F:〜/ Escritorio / Django / Ujixy $ git remote add origin https://github.com/PEREYO/Ujixy.git
jesus @ jesus -K52F:〜/ Escritorio / Django / Ujixy $ git pull origin master
remote:计数对象:3,完成。
remote:合计3(delta 0),重用0(delta 0)
解包对象:100%(3/3),完成。
从https://github.com/PEREYO/Ujixy
*分支大师 - > FETCH_HEAD
jesus @ jesus-K52F:〜/ Escritorio / Django / Ujixy $ git push origin master
'https://github.com'的用户名:PEREYO
'https:/ /PEREYO@github.com':
所有最新的
jesus @ jesus-K52F:〜/ Escritorio / Django / Ujixy $ git init
在/ home / jesus / Escritorio / Django / Ujixy / .git /
jesus @ jesus-K52F:〜/ Escritorio / Django / Ujixy $ git add *
jesus @ jesus-K52F:〜/ Escritorio / Django / Ujixy $ git status
#在分支master上
没有提交(工作目录干净)

现在我正试着修复它:

  jesus @ jesus-K52F:〜/ Escritorio / Ujixy $ git fsck --lost-found 
检查对象目录:100%(256/256),完成。
dangling tree bfe11a30d57a0233d3b0c840a3b66f6421987304
jesus @ jesus-K52F:〜/ Escritorio / Ujixy $ git status
分支主
无需提交(工作目录干净)
耶稣@ jesus-K52F:〜/ Escritorio / Ujixy $ git reflog
61daa69 HEAD @ {0}:初始拉

jesus @ jesus-K52F:〜/ Escritorio / Ujixy $ git cat-file -p bfe11a30d57a0233d3b0c840a3b66f6421987304
040000树9196501a346cfe4347f46d82936745b78b0235b9 Catalogoapp
040000树49561b4bd6adb8fe8bb1915d6bef09cd49195a97 Messageapp
040000树0fb58bf9b56397443fb235e2a38045d6df7cd473 Ujixyapp
100644一滴e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 __init__.py
100644一滴dfe3388ddf2d5ba34559eb3ec56199d83cdce8bd __init __。PYC
100644 blob bcdd55e27be9447bf6b224b8ba0cbc6802509862 manage.py
100644 blob 34c5978d8026844038d530b491828398bc3ea6c7 settings.py
100644 blob 167a6b1965426ec30c25535fe27338b61b2ae0cf settings.pyc
100644 blob 4a7215cb90ae95d64ca30fd e1c1277e0155eb4ed urls.py
100644 blob 6eedcddafbc8854f70f44181edac8e63781cfb09 urls.pyc

但是,如何恢复包含所有文件和文件夹的目录?现在我正在使用.git文件夹的副本来避免另一个问题。

摇晃树木的物体,你很好。以下内容应该可以工作:首先将悬挂树恢复为Git的索引:

  git read-tree bfe11a30d57a0233d3b0c840a3b66f6421987304 

接下来,从现在恢复的索引中更新您的工作目录:

  git checkout-index -a 


It was the first time that I was using git, I wanted to import an existing project into github and everything was deleted. After search for an answer I think git deleted the files after git pull, I'm trying to recover the files and folders but I can't find how to do it.

I did exactly the next:

jesus@jesus-K52F:~/Escritorio/Django/Ujixy$ git init
Initialized empty Git repository in /home/jesus/Escritorio/Django/Ujixy/.git/
jesus@jesus-K52F:~/Escritorio/Django/Ujixy$ git add .
jesus@jesus-K52F:~/Escritorio/Django/Ujixy$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   Catalogoapp/__init__.py
#   new file:   Catalogoapp/models.py
#   new file:   Catalogoapp/tests.py
#   new file:   Catalogoapp/views.py
#   new file:   Messageapp/__init__.py
#   new file:   Messageapp/models.py
#   new file:   Messageapp/tests.py
#   new file:   Messageapp/views.py
#   new file:   Ujixyapp/__init__.py
[...]

jesus@jesus-K52F:~/Escritorio/Django/Ujixy$ git push origin master
fatal: 'origin' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
jesus@jesus-K52F:~/Escritorio/Django/Ujixy$ git add *
jesus@jesus-K52F:~/Escritorio/Django/Ujixy$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   Catalogoapp/__init__.py
#   new file:   Catalogoapp/models.py
#   new file:   Catalogoapp/tests.py
#   new file:   Catalogoapp/views.py
#   new file:   Messageapp/__init__.py
#   new file:   Messageapp/models.py
#   new file:   Messageapp/tests.py
#   new file:   Messageapp/views.py
#   new file:   Ujixyapp/__init__.py
[...]
jesus@jesus-K52F:~/Escritorio/Django/Ujixy$ git remote add origin https://github.com/PEREYO/Ujixy.git
jesus@jesus-K52F:~/Escritorio/Django/Ujixy$ git pull origin master
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From https://github.com/PEREYO/Ujixy
* branch            master     -> FETCH_HEAD
jesus@jesus-K52F:~/Escritorio/Django/Ujixy$ git push origin master
Username for 'https://github.com': PEREYO
Password for 'https://PEREYO@github.com': 
Everything up-to-date
jesus@jesus-K52F:~/Escritorio/Django/Ujixy$ git init
Reinitialized existing Git repository in /home/jesus/Escritorio/Django/Ujixy/.git/
jesus@jesus-K52F:~/Escritorio/Django/Ujixy$ git add *
jesus@jesus-K52F:~/Escritorio/Django/Ujixy$ git status
# On branch master
nothing to commit (working directory clean)

Now I'm trying to fix it doing the next:

jesus@jesus-K52F:~/Escritorio/Ujixy$ git fsck --lost-found
Checking object directories: 100% (256/256), done.
dangling tree bfe11a30d57a0233d3b0c840a3b66f6421987304
jesus@jesus-K52F:~/Escritorio/Ujixy$ git status
# On branch master
nothing to commit (working directory clean)
jesus@jesus-K52F:~/Escritorio/Ujixy$ git reflog
61daa69 HEAD@{0}: initial pull

jesus@jesus-K52F:~/Escritorio/Ujixy$ git cat-file -p bfe11a30d57a0233d3b0c840a3b66f6421987304
040000 tree 9196501a346cfe4347f46d82936745b78b0235b9    Catalogoapp
040000 tree 49561b4bd6adb8fe8bb1915d6bef09cd49195a97    Messageapp
040000 tree 0fb58bf9b56397443fb235e2a38045d6df7cd473    Ujixyapp
100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391    __init__.py
100644 blob dfe3388ddf2d5ba34559eb3ec56199d83cdce8bd    __init__.pyc
100644 blob bcdd55e27be9447bf6b224b8ba0cbc6802509862    manage.py
100644 blob 34c5978d8026844038d530b491828398bc3ea6c7    settings.py
100644 blob 167a6b1965426ec30c25535fe27338b61b2ae0cf    settings.pyc
100644 blob 4a7215cb90ae95d64ca30fde1c1277e0155eb4ed    urls.py
100644 blob 6eedcddafbc8854f70f44181edac8e63781cfb09    urls.pyc

But, How can I recover the directories with all the files and folder? Now I'm working in a copy of .git folder to avoid another problems.

解决方案

As you already have a reference to a dangling tree object, you're well on your way. The following should work: first recover the dangling tree into Git's index:

git read-tree bfe11a30d57a0233d3b0c840a3b66f6421987304

Next, update your working directory from the now-recovered index:

git checkout-index -a

这篇关于git删除了所有内容,如何恢复文件和文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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