Data corruption using git

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.

  • overwritten git repo with old version of git repo, game over?
  • How can I recover HEAD^'S tree?
  • Recover files from an Rails app through git cloning the heroku app?
  • git “error: corrupt loose object” after moving a directory
  • How to recover Git objects damaged by hard disk failure?
  • Recovering Git repository from objects only
  • One Solution collect form web for “Data corruption using git”

    Thanks Makato. I voted your comment up.
    I came up with my own quick and dirty solution.

    1. 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)

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

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

    4. 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)

    5. I pasted the commit string I copied earlier and saved the file.

    6. I ran a git status, and it stated my branch was ahead of origin/master by 29 commits.

    7. I pushed my commits.

    8. Ran another git commit, and it committed changes that should have been in that corrupt commit.

    9. Now I am back to where I left off.

    I hope this helps anyone that experiences this problem.

    Git Baby is a git and github fan, let's start git clone.