sscirrus
sscirrus

Reputation: 56779

Badly corrupted git repository

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

Debug begins:

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

Now I run:

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    

What else can I try?


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

Of course, git fsck returns the same errors.

Upvotes: 3

Views: 4473

Answers (2)

叉叉敌
叉叉敌

Reputation: 392

I met the same issue.

and delete the whole git repo, and run "repo sync" again.

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)

at first, you must find out where the repo is

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

Upvotes: 0

sscirrus
sscirrus

Reputation: 56779

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:

Prior to restore

  • Copied all data I could from gitk summarizing committed + uncommitted changes to a separate text file.
  • Opened two copies of gitk (for safety) and left them open for future reference.

Restore

  • 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.

Result

  • Completely clean git repo updated to the state it was at before detecting the corruption.

I hope this is helpful for you.

Upvotes: 1

Related Questions