严重损坏的git存储库

时间:2015-04-05 07:39:23

标签: git

接下来的内容很长,所以简而言之:我有一个严重损坏的回购,我有备份,我想恢复稳定状态,所以我可以恢复文件(如果必须,我可以手动恢复)。我将整个存储库复制到另一个包含我的更改列表的文件夹中,因此如果一切都变坏,我可以轻松手动传输。

我首先尝试提交代码并获得:

error: invalid object 100644 e9fede64cd0e6499fb3740d81d45d14768b27ffb for 'app/views/free_emp_opinions/new.html.erb'
error: invalid object 100644 e9fede64cd0e6499fb3740d81d45d14768b27ffb for 'app/views/free_emp_opinions/new.html.erb'
error: Error building trees

我使用备份手动替换了该文件,然后得到:

error: invalid object 100644 e6317da4299554ce7eb39e9baa0b49d4b30743db for 'app/views/link_groups/show.html.erb'
error: invalid object 100644 e6317da4299554ce7eb39e9baa0b49d4b30743db for 'app/views/link_groups/show.html.erb'
error: Error building trees

调试开始:

git status
fatal: unable to read e9fede64cd0e6499fb3740d81d45d14768b27ffb

git prune
error: Could not read ef528d9533bb296f0ff528551527b787cfd3c888
fatal: bad tree object ef528d9533bb296f0ff528551527b787cfd3c888

git reset --hard
error: unable to read sha1 file of app/views/free_emp_opinions/new.html.erb (e9fede64cd0e6499fb3740d81d45d14768b27ffb)
error: unable to read sha1 file of app/views/link_groups/show.html.erb (e6317da4299554ce7eb39e9baa0b49d4b30743db)
fatal: Could not reset index file to revision 'HEAD'.

现在我跑:

git fsck --full
Checking object directories: 100% (256/256), done.
Checking objects: 100% (26833/26833), done.
broken link from    tree 0a6b00e8d1937c3e31c5e75d9de939c97adc205f
              to    blob e9fede64cd0e6499fb3740d81d45d14768b27ffb
broken link from    tree 367acd2750e703d44cb76403ea74c69d02130e09
              to    tree ef528d9533bb296f0ff528551527b787cfd3c888
broken link from    tree 0b7c7ac1d8475b355d2f382d1220dd0a53dc83ac
              to    blob e02d8b0123c0891206f9fb9f43c1ec7b3e32495b
broken link from    tree 2c4b398e161573622d6d50b96d31084209325569
              to    tree dc1eace38a6510ef25cb7d0b5debf5216fccd948
broken link from    tree 2c4b398e161573622d6d50b96d31084209325569
              to    tree e2dca328dac5f632b1c768e6e52767aef11f0266
broken link from    tree 479d84ae8cd3a0bf0ff8f28da4b41f9fe3cd793c
              to    blob e70452a6561eabbc568e5e23acf30ea84dd4fba4
broken link from    tree 49cdccd88608729674cad489d1a93f4a210f96ca
              to    tree e4172bffc23b279fd6e98b5831179bac26109ebb
broken link from  commit 4310cd9376a2f633ac26b29e90c472cf14f60765
              to    tree e3071ddca12fa64996ff0ab2cf7b7511e57c42c1
dangling blob 1a011db92445954272ddd5529316023fbbe607e4
dangling blob 5201c769001b1032c052d2fa81831ae9f6c525dd
dangling blob 7c023ab3a58f916f7871b525c23233e8386fa1a8
dangling blob 5d03033fee1d65ff431548c8b2a678ea250dbb90
dangling commit c5030fe567bc734d2c7381b24d196d2d68e8cfa8
dangling blob b504169a1d1cffc2646eb4ba75d0e65df2d4932f
missing blob e70452a6561eabbc568e5e23acf30ea84dd4fba4
dangling blob d6058a10a39afa230991fd633482ac0e768ea383
dangling blob 4606c7d01b21621c70393beb0000c174ddf038dc
missing tree e3071ddca12fa64996ff0ab2cf7b7511e57c42c1
dangling blob af1111e218aba1a936c20a69b35a529efa8d959a
dangling blob 59126b4617ac8cae1cabfd209396a276c796724a
dangling blob ea12b047dc5c8cd0ae5b6f446b09a49d2f066902
...another 60+ issues...

git reset --hard HEAD@{1}
error: unable to read sha1 file of app/views/free_emp_opinions/new.html.erb (e9fede64cd0e6499fb3740d81d45d14768b27ffb)
error: unable to read sha1 file of app/views/link_groups/show.html.erb (e6317da4299554ce7eb39e9baa0b49d4b30743db)
fatal: Could not reset index file to revision 'HEAD@{1}'.

我尝试了其他人提出的一些建议:

git log | head
commit e89d926275c25e1ed859a5c00c870a69cf857ce0
Author: sscirrus <***>
Date:   Wed Mar 18 16:44:04 2015 -0400
Tweak: change emphome job rightmost readout from date first posted to date of last activity

commit a0d97a6a5308a2b18504fa3394fea7efa43c06b0
Author: sscirrus <***>
Date:   Wed Mar 18 13:25:49 2015 -0400    

我还能尝试什么?


在@ jsexpert的建议之后,我跑了:

git gc --prune=now
error: Could not read ef528d9533bb296f0ff528551527b787cfd3c888
fatal: bad tree object ef528d9533bb296f0ff528551527b787cfd3c888
error: failed to run repack

当然,git fsck会返回相同的错误。

2 个答案:

答案 0 :(得分:1)

由于存储库中的错误数量以及无法运行git gcgit status等命令,我执行了以下操作:

恢复之前

  • 将我可以从gitk复制的所有数据汇总为已提交的+未提交的更改到单独的文本文件。
  • 打开两份gitk(为安全起见)并将其打开以备将来参考。

恢复

  • 使用Time Machine(OS X)查找将响应git gc的最新备份(大约一周前)。
  • 备份当前损坏的存储库。
  • 在当前仓库顶部恢复了干净备份。
  • 使用文本文件手动复制/粘贴备份顶部的更改。

结果

  • 完全清理git repo,更新到检测到损坏之前的状态。

我希望这对你有所帮助。

答案 1 :(得分:0)

我遇到了同样的问题。

并删除整个git repo,然后再次运行“ repo sync”。

Syncing work tree:  91% (817/897)error: unable to read sha1 file of AdaptiveStudioLite-linux.gtk.x86_64.zip (9406a46cf9580567faf3f8bdf69abfa7cfeda364)
error: unable to read sha1 file of adaptiveStudioScript.sh (fe8b65c44d9b8f24f471a45823a4d71654bf9661)

首先,您必须找出存储库在哪里

rm -rfv AdaptiveStudio.git
repo sync -f -c -j8