git删除了所有内容,如何恢复文件和文件夹

2023-11-22

这是我第一次使用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(使用前将#替换为@)

git删除了所有内容,如何恢复文件和文件夹 的相关文章

  • 在 Azure DevOps 项目之间移动存储库时保留拉取请求

    我在同一帐户内有两个 Azure DevOps 项目 我想将存储库从一个项目移动到另一个项目 这一页探索如何在具有完全保真历史记录的团队项目之间移动 git 存储库 https learn microsoft com en us azure
  • GIT:以下未跟踪的工作树文件将被签出覆盖

    我有两个分支 一个称为 master 另一个称为 dev 我目前位于 master 分支 我想转到 dev 分支将文件移动到开发服务器 但是当我执行 git checkout dev 我收到消息 以下未跟踪的工作树文件将被覆盖 查看 pag
  • Github Action 在运行可执行文件时卡住

    我正在尝试设置运行google tests on a C repository using Github Actions正在运行的Windows Latest 构建过程完成 但是当运行测试时 它被卡住并且不执行从生成的可执行文件Visual
  • Git difftool 未启动外部 DiffMerge 程序

    我一直遵循 戴夫的博客条目 http www davesquared net 2009 05 setting up git difftool on windows html 链接在此answer https stackoverflow co
  • 为所有子文件夹设置 git 配置值

    我知道可以设置每个存储库的配置来覆盖用户级配置 即 path to my repo gitconfig覆盖 gitconfig 是否可以设置 git 配置来覆盖给定文件夹的所有子文件夹的用户级设置 即 我有 topLevelFolder1
  • Git 到 TFS 源代码管理迁移

    我想看看 TFS 如何为我的命令工作 所以我想将我们当前的 GIT 存储库移动到 TFS 数据库 我们使用 GIT 来获得普遍的分支支持 因此我想使用 TFS 2010 来解决该问题 现在的问题是 如何将 GIT 存储库导出到 TFS 显然
  • 无法通过 Git Bash 克隆 git 存储库

    在尝试使用克隆存储库时git clone 它显示以下错误 致命 无法访问 https github com microsoft c9 python getting started git https github com microsoft
  • 为什么 Git 无法将文件更改与修改后的父级/主控合并?

    我有一个文件 里面只有一行 我创建一个分支并向同一文件添加第二行 保存并提交到分支 我切换回主人 并向文件中添加不同的第二行 保存并提交给master 现在总共有 3 条独特的线路 如果我现在尝试将分支合并回主分支 则会遇到合并冲突 为什么
  • Github - 上传文件

    我正在尝试将文件夹添加到 github 存储库 该文件在 github 上显示为空 并有一个绿色箭头 有谁知道如何解决这个问题 我将不胜感激你的帮助 谢谢 这看起来类似于 Git 如何跟踪未跟踪的内容 https stackoverflow
  • git 是否有任何静态接口?

    我一直在寻找一个宁静的 git api 但似乎没有找到 我得到的最接近的是 Github 的 api 来访问一些存储库信息 还有其他的实施吗 Orion Git API http wiki eclipse org Orion Server
  • 部分共享git仓库

    我是 git 新手 我想知道是否支持以下场景 如果支持的话如何支持 即用于设置和更新的 git 命令 可以从三个不同的地方获取存储库 本地 镜像 和 github mirror 完全镜像 local github 镜像 local 但 受版
  • VSTS:在构建过期的情况下自动变基/合并和重新排队构建验证门

    我们最近对 PR 上的构建验证门进行了更改 这样 如果另一个提交在当前 PR 完成之前进入主分支 则构建会 立即 过期 看here https stackoverflow com questions 49418800 vsts invali
  • BRISK 特征检测器检测零个关键点

    下面显示的 Brisk 探测器没有给我任何关键点 有人可以提出一个问题吗 我将尝试用一些代码解释我在下面所做的事情 include opencv2 features2d features2d hpp using namespace cv u
  • 如何使用git-svn切换svn分支?

    复制 如何让 git svn 使用特定的 svn 分支作为远程存储库 https stackoverflow com questions 192736 how do i make git svn use a particular svn b
  • Git 工作流程:分叉项目并维护本地修改副本,但保持最新

    我正在尝试找出最佳工作流程 用于维护具有自定义功能的 github 托管项目 moodle 的本地副本 同时保持保持副本最新的能力 告诉我我正在考虑做的事情是否完全疯狂 分叉项目 github com moodle moodle gt gi
  • MSysGit 与 Windows 版 Git

    我无法确定MSysGit 和 Windows 版 Git 之间的区别 http msysgit github com 它们有何不同 为什么我会选择其中之一而不是另一个 它们不是同一个东西吗 On http msysgit github co
  • Travis CI 可以在同一存储库的不同分支中使用加密文件吗?

    我正在尝试让 Travis CI 构建在我自己的私人分支和我组织的存储库中工作 我使用以下方法加密了配置文件travis encrypt file命令 它似乎在我自己的 fork 的 travis 设置中创建了两个环境变量 如下所示 加密
  • 删除 Git 存储库,但保留所有文件

    在我使用 Linux 的过程中的某个时刻 我决定将我的主目录中的所有内容都放入源代码管理中是个好主意 我不是在问这是否是一个好主意 我是在问如何撤销它 删除存储库的原因是我最近安装了 Oh My Zsh 而且我非常喜欢它 问题是我的主目录有
  • 从 GitHub 读取代码作为网页中的文本(原始)

    我正在尝试从我的 GitHub 存储库读取一些源代码 C 语言 以在我的网页中显示为文本 我可以通过以下方式访问原始模式下的代码https raw github com https raw github com 我正在使用 jQuery G
  • 具有单个子模块的多个存储库

    我已经找了一段时间但没有找到答案 也许我不知道该看什么 我们有一个主库 它本身就是一个存储库 我们称之为 Lib 它包含我们的大部分模块和子模块 我们还假设它的大小为 2GB 现在我们有很多项目 例如 ProjA ProjB ProjC 每

随机推荐