GIT Status Error & Solution - exam105/backend GitHub Wiki
Issue
muhammad@muhammad:~/$ git status
error: object file .git/objects/ab/22d9d3d8148e2170702ef275eb975e5d6d276c is empty
error: object file .git/objects/ab/22d9d3d8148e2170702ef275eb975e5d6d276c is empty
error: object file .git/objects/ab/22d9d3d8148e2170702ef275eb975e5d6d276c is empty
fatal: loose object ab22d9d3d8148e2170702ef275eb975e5d6d276c (stored in .git/objects/ab/22d9d3d8148e2170702ef275eb975e5d6d276c) is corrupt
Cause of issue
This issue can arise if files are damaged by an improper shutdown of a computer/VM for any reason. Other possible reasons can be operating system crashes, power failures, computers catching on fire.
If you have unstaged or staged files then those will be corrupted.
Solution
This can be solved by the following commands
- find .git/objects/ -size 0 -exec rm -f {} ;
- git fetch origin
- git symbolic-ref HEAD refs/heads/master or main
- git status
- Stash changes
- Create a new or temp branch standing at main
- Apply stash to the new branch
Ref: https://stackoverflow.com/questions/4254389/git-corrupt-loose-object [Check Felipe Pereira answer]
The branch exam105-48 is not valid anymore.
muhammad@muhammad:~/$ git fsck
Checking object directories: 100% (256/256), done.
Checking objects: 100% (12/12), done.
error: refs/heads/exam105-48: invalid sha1 pointer ab22d9d3d8148e2170702ef275eb975e5d6d276c
dangling blob 4b34aa9881498cf7e379b36b54abcf3701fbc676
dangling blob a56854fa51d689820a29fb8f0a285fea125bada5
dangling blob a874504ebe9503bf0e2f2876ed36145c8dae76be
dangling commit 08e92559ddbe0b31bac079aa82766fc510b0935c
dangling commit c1b10680b2cc7659a16c107f8cd5ca858f13b0fb
dangling commit c097143dea36dcde71abb91da10437506d8d8616
dangling blob d4078f68917c361fa0ad66aac0459e2fc716689a
The line error: refs/heads/exam105-48 is showing that the branch has been corrupted. To remove this branch's reference from git, use the following command
Remove the branch reference using following command
rm .git/refs/heads/exam105-48