Reputation: 146
I was working on a project and experienced hardware failure. I have about 30 commits I did not get to push before this happened. I recovered from the crash and checked my repo. I now get this error message from a git status
.
error: object file .git/objects/a8/f43fd5a872feda2a771e6a1ced1518f455d9f3 is empty
error: unable to find a8f43fd5a872feda2a771e6a1ced1518f455d9f3
error: object file .git/objects/a8/f43fd5a872feda2a771e6a1ced1518f455d9f3 is empty
fatal: loose object a8f43fd5a872feda2a771e6a1ced1518f455d9f3 (stored in .git/objects/a8/f43fd5a872feda2a771e6a1ced1518f455d9f3) is corrupt
How can I remove this empty object and not get an error message from the HEAD?
I tried manually removing the bad object, but got this error:
fatal: could not parse HEAD
Thank you in advance.
Upvotes: 2
Views: 268
Reputation: 146
Thanks Makato. I voted your comment up. I came up with my own quick and dirty solution.
I went to ~/my_project/.git/logs/refs/heads/ In that directory used sublime text editor to open the file named: master (this file contains a history of commits)
I went to the last line of code. It contained NULL, NULL, NuLL repeated over and over again. I deleted it and saved the file.
In the last good line of commits you will see 2 commit strings with 40 characters in each string. I copied the second string of characters.
I went to this directory next. ~/my_project/.git/refs/heads In that directory used sublime text editor to open the file named: master (this file contains the last commit in your history)
I pasted the commit string I copied earlier and saved the file.
I ran a git status, and it stated my branch was ahead of origin/master by 29 commits.
I pushed my commits.
Ran another git commit, and it committed changes that should have been in that corrupt commit.
Now I am back to where I left off.
I hope this helps anyone that experiences this problem.
Upvotes: 1