本文介绍了严重损坏的git存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

接下来的时间很长,所以简而言之:我有一个严重损坏的存储库,有备份,并且我想返回到稳定状态,以便可以恢复文件(如果需要,可以手动恢复).我将整个存储库复制到包含更改列表的另一个文件夹中,因此,如果所有操作都变糟,我可以轻松进行手动传输.

What follows is long, so here's the nutshell: I have a badly corrupted repo, I have backups, and I want to return to stable state so I can restore the files (manually if I have to). I copied the entire repository into another folder with a list of my changes, so I have an easy manual transfer if this all goes bad.

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

I first tried to commit code and got:

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

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

I manually replaced that file using a backup then got:

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}'.

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

I try some suggestions others have made:

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的建议之后,我跑了:

After @jsexpert's suggestion, I ran:

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

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

Of course, git fsck returns the same errors.

推荐答案

由于存储库中存在许多错误,并且完全无法运行 git gc git status ,我做了以下事情:

Due to the number of errors in the repository and a complete inability to run commands like git gc or git status, I did the following:

  • 将我可以从gitk中汇总的所有数据(汇总已提交的+未提交的更改)复制到一个单独的文本文件中.
  • 为了安全起见,打开了gitk的两个副本,并将它们打开以备将来参考.
  • 使用Time Machine(OS X)查找可以响应 git gc 的最新备份(大约一周前).
  • 备份当前损坏的存储库.
  • 将干净备份恢复到当前存储库的顶部.
  • 使用文本文件手动将更改复制/粘贴到备份的顶部.
  • Used Time Machine (OS X) to find the most recent backup that would respond to git gc (about a week ago).
  • Backed up the current corrupt repository.
  • Restored the clean backup on top of the current repo.
  • Used the text file to manually copy/paste the changes on top of the backup.
  • 完全干净的git repo已更新为检测到损坏之前的状态.

我希望这对您有帮助.

这篇关于严重损坏的git存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 21:06