My computer shut down suddenly and now the Git repository of the project which I worked on is defect. I have Git 2.20.1 installed. I immediately created a backup copy of the project folder to play around with the original. I have local branches which I do not want to loose.
$ git status
error: object file .git/objects/c7/8e67bcad2ea132e3df8f80bb42b4804ab4f2a3 is empty
fatal: loose object c78e67bcad2ea132e3df8f80bb42b4804ab4f2a3 (stored in .git/objects/c7/8e67bcad2ea132e3df8f80bb42b4804ab4f2a3) is corrupt
Shorted output:
$ git fsck --name-objects
error: object file .git/objects/04/f338bf0dc0770b841b291af6cdd4c9130edb84 is empty
error: unable to mmap .git/objects/04/f338bf0dc0770b841b291af6cdd4c9130edb84: No such file or directory
error: 04f338bf0dc0770b841b291af6cdd4c9130edb84: object corrupt or missing: .git/objects/04/f338bf0dc0770b841b291af6cdd4c9130edb84
error: object file .git/objects/2e/07479ec010e5b459387d841a576e1ead97f850 is empty
error: unable to mmap .git/objects/2e/07479ec010e5b459387d841a576e1ead97f850: No such file or directory
error: 2e07479ec010e5b459387d841a576e1ead97f850: object corrupt or missing: .git/objects/2e/07479ec010e5b459387d841a576e1ead97f850
error: object file .git/objects/34/b03409d09382c44f50409e4388850ca9c82c77 is empty
error: unable to mmap .git/objects/34/b03409d09382c44f50409e4388850ca9c82c77: No such file or directory
...
error: object file .git/objects/c7/8e67bcad2ea132e3df8f80bb42b4804ab4f2a3 is empty
error: unable to mmap .git/objects/c7/8e67bcad2ea132e3df8f80bb42b4804ab4f2a3: No such file or directory
error: c78e67bcad2ea132e3df8f80bb42b4804ab4f2a3: object corrupt or missing: .git/objects/c7/8e67bcad2ea132e3df8f80bb42b4804ab4f2a3
error: object file .git/objects/e5/19b2fbf083f68694af97ccddf46bc28c6ee8f7 is empty
error: unable to mmap .git/objects/e5/19b2fbf083f68694af97ccddf46bc28c6ee8f7: No such file or directory
error: e519b2fbf083f68694af97ccddf46bc28c6ee8f7: object corrupt or missing: .git/objects/e5/19b2fbf083f68694af97ccddf46bc28c6ee8f7
error: object file .git/objects/ec/289b8e8d17c47644d5bdbfbfc8b2957d2a430e is empty
error: unable to mmap .git/objects/ec/289b8e8d17c47644d5bdbfbfc8b2957d2a430e: No such file or directory
error: ec289b8e8d17c47644d5bdbfbfc8b2957d2a430e: object corrupt or missing: .git/objects/ec/289b8e8d17c47644d5bdbfbfc8b2957d2a430e
error: object file .git/objects/ed/33778ddc07a26a37c6f200f35ffee12e365ea4 is empty
error: unable to mmap .git/objects/ed/33778ddc07a26a37c6f200f35ffee12e365ea4: No such file or directory
error: ed33778ddc07a26a37c6f200f35ffee12e365ea4: object corrupt or missing: .git/objects/ed/33778ddc07a26a37c6f200f35ffee12e365ea4
error: object file .git/objects/f6/5686bed85025fd7adbf209ba93846b18800d70 is empty
error: unable to mmap .git/objects/f6/5686bed85025fd7adbf209ba93846b18800d70: No such file or directory
error: f65686bed85025fd7adbf209ba93846b18800d70: object corrupt or missing: .git/objects/f6/5686bed85025fd7adbf209ba93846b18800d70
error: object file .git/objects/fd/cdc518b01c670cd38c15903fd3e84554114d38 is empty
error: unable to mmap .git/objects/fd/cdc518b01c670cd38c15903fd3e84554114d38: No such file or directory
error: fdcdc518b01c670cd38c15903fd3e84554114d38: object corrupt or missing: .git/objects/fd/cdc518b01c670cd38c15903fd3e84554114d38
Checking object directories: 100% (256/256), done.
Checking objects: 100% (40855/40855), done.
error: refs/remotes/origin/colors-housekeeping: invalid sha1 pointer 0000000000000000000000000000000000000000
error: bad ref for .git/logs/refs/remotes/origin/colors-housekeeping
error: object file .git/objects/ec/289b8e8d17c47644d5bdbfbfc8b2957d2a430e is empty
fatal: loose object ec289b8e8d17c47644d5bdbfbfc8b2957d2a430e (stored in .git/objects/ec/289b8e8d17c47644d5bdbfbfc8b2957d2a430e) is corrupt
colors-housekeeping
is a branch which is already merged to master
and already I edited other files afterwards, committed and merged another branch.
What are the steps I can take to fix the corrupt objects?
git reflog --all
? – Bukegit fsck --lost-found
to make otherwise-inaccessible "blob" objects accessible via.git/lost-found/
. Their file names will generally be impossible to recover in an automated manner. – Bleedingls -ltr
on the.git/objects
directory to find out the lastest few objects that were touched. Depending on what you put in, there might be a commit, a few blobs and perhaps a few trees. If you can find the commit before that, you might be able to restore the repository to that state using a reset. Then manually take out the objects added since and inspect/repair them. – Ima