Skip to content

Instantly share code, notes, and snippets.

@dungsaga
Last active August 5, 2021 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dungsaga/908ed2425430aed8b611ec5ee88d5592 to your computer and use it in GitHub Desktop.
Save dungsaga/908ed2425430aed8b611ec5ee88d5592 to your computer and use it in GitHub Desktop.
fix corrupted git repo

check for errors

git fsck --full

error: HEAD: invalid reflog entry 9fa7d8a22a680f8cf76e560ddb9e910419936006
error: refs/heads/local-api: invalid reflog entry c26cc0ae14632bd6a6d09aeb8973f97ccfc3035c
error: object file .git/objects/6b/f03a2e38b9cf909eff2500c14fce48a61d2965 is empty
error: object file .git/objects/6b/f03a2e38b9cf909eff2500c14fce48a61d2965 is empty
fatal: loose object 6bf03a2e38b9cf909eff2500c14fce48a61d2965 (stored in .git/objects/6b/f03a2e38b9cf909eff2500c14fce48a61d2965) is corrupt

remove empty objects

https://stackoverflow.com/questions/11706215/how-to-fix-git-error-object-file-is-empty/12371337#12371337

find .git/objects/ -type f -empty | xargs rm

find .git/objects/ -size 0 -exec rm -f {} \
@dungsaga
Copy link
Author

dungsaga commented Jul 27, 2021

  • fix corrupted objects referred by branches (in refs/**)
  • fix corrupted objects found in reflog (in packed-refs and logs/**)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment