【问题标题】:Problems with corrupt git repo损坏的 git repo 的问题
【发布时间】:2013-01-12 05:06:25
【问题描述】:

我的 git 存储库在运行查找和替换命令时损坏(请参阅此处:Git reset failing after find and replace)。所以我删除了一些 git 告诉我无法访问的包文件。所以我跑了 rm ./.git/index, git reset。运行 git commit 时,我收到此消息:

fatal: corrupt tree sha $someSHA

最后 git fsck,我的工作目录变干净了,我可以提交了。现在的 pb 是当我运行 git checkout some_other_branch 时,我收到了这条消息

fatal: unable to read tree $someSHA

(出现的 $someSHA 相同)。有人可以帮助我吗?

编辑1:

当我运行 git fsck --full 时,我得到一系列

error: refs/remotes/repo0/master does not point to a valid object!
error: refs/remotes/repo1/new-version does not point to a valid object!
...

然后是一系列

broken link from    tree d935b909f76ea92728d71038d0a67384353e65e1
              to    blob 05b97658ebd47fee25b76d80ac76cbd07d77961d
...

然后是一些丢失的 blob...

编辑2:

我运行了 git log --raw --all --full-history --subdir/my-file,我得到了

error: refs/remotes/repo0/master does not point to a valid object!
error: refs/remotes/repo1/new-version does not point to a valid object!
...
error: Could not read 9096eb9d9dcbdf15a04e0a7c78a3744936f82ac7
fatal: cannot simplify commit 8dfd8e3d5b698dc979300d93d8e89a757abf6ec6 (because of 9096eb9d9dcbdf15a04e0a7c78a3744936f82ac7)

编辑 3:

我跑了git fsck --full,所以我得到了很多行

error: packfile .git/objects/pack/pack-fbfd8042e1e96bf5ffff88f9b5a230b8f5e4d4c4.pack does not match index
fatal: packfile .git/objects/pack/pack-fbfd8042e1e96bf5ffff88f9b5a230b8f5e4d4c4.pack cannot be accessed
...

当将git checkout 运行到另一个分支时,我收到了很多消息:

error: packfile .git/objects/pack/pack-3e7a0c040a5e3d1c21b91256d583424d82a59706.pack does not match index
warning: packfile .git/objects/pack/pack-3e7a0c040a5e3d1c21b91256d583424d82a59706.pack cannot be accessed
....
fatal: unable to read tree 2ad71d368b65eff0b6fec1ef72c6fdde6e80edad

编辑 4:

按照建议的答案,我解压缩了文件,当我签出时,我得到了 一些这样的行:

error: packfile .git/objects/pack/pack-fbfd8042e1e96bf5ffff88f9b5a230b8f5e4d4c4.pack does not match index
warning: packfile .git/objects/pack/pack-fbfd8042e1e96bf5ffff88f9b5a230b8f5e4d4c4.pack cannot be accesse....

然后是一系列以

开头的行
 error: Your local changes to the following files would be overwritten by checkout:
.idea_local_work/.name
.idea_local_work/libraries/sass_stdlib.xml
.idea_local_work/scopes/scope_settings.xml
... and then aborting

【问题讨论】:

  • 你做了什么?!?!?为什么你认为删除包文件是个好主意?你有这些包文件的备份,还是你把你的东西推送到任何地方?
  • 是的,我有一些备份,我可以用它们做什么?
  • @Chronial 我对丢失当前分支中的所有数据没有任何问题。我只想回到另一个分支。你觉得这可能吗?
  • 把你的包文件放回你的仓库,git需要它们:)。还是您通过更改内容来破坏它们?你想回到你已经推送的分支吗?
  • 确实,我的备份中有包文件。我想离开我当前所在的分支,我可以松开它,因为我在某个远程仓库中有它,然后转到另一个关键分支,我的远程没有,但只有我的本地。你觉得还有希望吗?

标签: git git-checkout


【解决方案1】:

首先:备份您的.git 目录,以防在此过程中损坏更多内容。那么:

  • 放回可用的包文件的最佳版本。
  • 对于每个损坏的包文件,运行:

    mv .git/objects/pack/pack-**yourpack**.pack oldpack
    git unpack-objects -r < oldpack
    
  • 再次运行git fsck --fullgit checkout,给我们输出。

  • 看起来现在您应该能够签出,但您必须运行 git checkout -f **yourbranch**,因为您的工作目录中有尚未提交的更改。但是,当您运行 git checkout -f 时,这些更改将会丢失。

【讨论】:

  • 我开始运行你的命令,在放这个 git unpack-objects -r
  • 是的,解压所有报告为损坏的包文件。如果您愿意,可以将它们命名为 oldpack2 等。
  • (在聊天中添加了更多信息)
  • 编写了解压所有此类“无法访问”的包文件的脚本:gist.github.com/kirikaza/6178695#file-fix-git-packfiles-sh.
  • 必须运行 git unpack-objects -r &lt; oldpack 而不是 git-unpack-objects -r &lt; oldpack
【解决方案2】:

使用此存储库的另一个 .git 副本中的相同文件重写此文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-13
    • 2011-02-12
    • 2012-03-05
    • 1970-01-01
    • 1970-01-01
    • 2017-03-02
    相关资源
    最近更新 更多