How to fix

Git: «Corrupt loose object»

git

Also you can see something like this in you terminal:

error: object file .git/objects/03/9e5691db59686e2afce2da700853398c961b4a is empty

After the computer crashes, git showed:

$ git status
error: object file .git/objects/03/9e5691db59686e2afce2da700853398c961b4a is empty
error: object file .git/objects/03/9e5691db59686e2afce2da700853398c961b4a is empty
fatal: loose object 039e5691db59686e2afce2da700853398c961b4a (stored in .git/objects/03/9e5691db59686e2afce2da700853398c961b4a) is corrupt

Git is a control version system. So if we can’t fix internal git structure – we can’t access other versions of our project. Basicly we can run git command:

git fsck

If it doesn’t work, we can get the version of remote server (always synconize your local repository with remote!):

$ rm -rf .git
$ git init
$ git remote add origin REMOTE_SERVER_ADDRESS
$ git fetch
$ git reset --hard origin/master

It will override your local files and replace it with files from remote server.

What have we learned today?

  • Commit all changes (one simple feature = one commit).
  • Always push our commits to the remote server.
  • Each big feature should have it’s own branch (syncronized with the remote server).