How to diagnose and fix git fatal: unable to read tree

Viewed 109816

I'm using git to manage files on a project, and keep running into this problem.

When I run git status I get the message

fatal: unable to read tree e2d920161d41631066945a3cbcd1b043de919570

As I understand it, I should check the output of git fsck, and I receive

broken link from    tree e09a42f248afff64336fbbec2523df97c26451ac
              to    tree e2d920161d41631066945a3cbcd1b043de919570
broken link from    tree e09a42f248afff64336fbbec2523df97c26451ac
              to    tree 9b0dd389bd7f9e8d257395d57e0881b7957f9698
broken link from    tree e09a42f248afff64336fbbec2523df97c26451ac
              to    tree 9e288a4ad60d63f342dfd18237980674426aa725
broken link from    tree e09a42f248afff64336fbbec2523df97c26451ac
              to    tree 2a04647337089f554fab8c49cfd37149e5f4fc9f
broken link from    tree e09a42f248afff64336fbbec2523df97c26451ac
              to    tree ea16658b45ce961adc3c3f519b0e8d9672918ca8

together with a lot of missing blob messages.

Following various resources (e.g Git - Broken Links, Missing & Dangling Trees) I have simply re-cloned the project from github and started again.

Once I have re-cloned the project, all is good for a few commits, and then the problem arises again. Re-cloning every time doesn't seem to be optimal, and seems to go against the idea of using git, and I'd like to try and understand what is going on. How can I diagnose and fix this problem?

6 Answers

A bit funny, but it's possible this will help someone.

I just bought a new computer and my repository was in a Dropbox folder. Turns out the .git folder was still syncing as I was trying to get to work. Once the folder finished syncing, everything was normal.

I got the same git error and had tried the git fsck but nothing changed--still get the same fatal: unable to read tree ... message.

So I just checked out to a new branch called develop (you can name whatever it is), completed some tasks on that branch then committed code back to remote repo again (into develop branch).

After that, I pulled the remote master into local then merged it into develop branch using:

$ git pull origin master --allow-unrelated-histories

Then checkout back to master branch then merged with develop branch again.

This time I tried to push code to the remote master branch, fortunately, the problem was solved. There was no more fatal: unable to read tree message again.

Related