这是我第一次使用git,我想将现有的项目导入github,然后所有内容都被删除了。搜索答案后,我认为 git 在 git pull 后删除了文件,我正在尝试恢复文件和文件夹,但我找不到如何执行此操作。
我做了下一个:
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://[email protected]':
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)
现在我正在尝试通过下一步修复它:
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
但是,如何恢复包含所有文件和文件夹的目录?现在我正在使用 .git 文件夹的副本以避免出现其他问题。
由于您已经有了对悬空树对象的引用,因此您已经顺利进行了。以下应该可行:首先将悬挂树恢复到 Git 的索引中:
git read-tree bfe11a30d57a0233d3b0c840a3b66f6421987304
接下来,从现在恢复的索引更新您的工作目录:
git checkout-index -a
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)