2

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.

Makoto
  • 104,088
  • 27
  • 192
  • 230
user3386050
  • 146
  • 1
  • 10
  • 1
    [This question](http://stackoverflow.com/questions/4254389/git-corrupt-loose-object) and [this question](http://stackoverflow.com/questions/11597003/how-to-remove-fatal-loose-object) are likely going to be helpful for you. – Makoto Oct 25 '14 at 16:13
  • 1
    possible duplicate of [How to recover Git objects damaged by hard disk failure?](http://stackoverflow.com/questions/801577/how-to-recover-git-objects-damaged-by-hard-disk-failure) – Andrew C Oct 25 '14 at 16:16
  • My problem as a little simpler. I just did the steps below. Thank you for the consideration. – user3386050 Oct 25 '14 at 17:23

1 Answers1

1

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.

user3386050
  • 146
  • 1
  • 10