Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git commit stopped working - Error building trees

Tags:

git

I can not commit a change:

$ git commit
error: invalid object 100644 13da9eeff5a9150cf2135aaed4d2e337f97b8114 for 'spec/routing/splits_routing_spec.rb'
error: Error building trees

I tried so far:

$ git fsck | grep 13da
missing blob 13da9eeff5a9150cf2135aaed4d2e337f97b8114

and also:

$ git prune
error: Could not read 1394dce6fd1ad15a70b2f2623509082007dc5b6c
fatal: bad tree object 1394dce6fd1ad15a70b2f2623509082007dc5b6c

and also:

$ git fsck | grep 13da
missing blob 13da9eeff5a9150cf2135aaed4d2e337f97b8114

but nothing helped. Should I delete the file, commit and reintroduce back? I am willing to lose little bit of history if it brings git commit back.

like image 884
gorn Avatar asked Jan 21 '13 22:01

gorn


4 Answers

This error means that you have a file with hash 13da9eeff5a9150cf2135aaed4d2e337f97b8114, and this hash is not present in .git/objects/../, or it's empty. When this error occurred, I only had this hash in the error, without the file path. Then I tried to do git gc --auto and git reset --hard. After one of these commands (these commands did not fix my problem), I got the path of the file that triggers the error.

You just need to generate the object hash:

git hash-object -w spec/routing/splits_routing_spec.rb

For more information see documentation. In the documentation, there is an additional way of repairing this error.

P.S. This was the only way that was helpful for me.

like image 114
Alex Nikulin Avatar answered Nov 18 '22 12:11

Alex Nikulin


You might have a corrupted object in your git repository.

If you have a remote, or other clones of this repository, you could grab from there the problematic file and just replace it on your local repo.

The file you want would be in:

/repo/.git/objects/13/da9eeff5a9150cf2135aaed4d2e337f97b8114
like image 22
Maic López Sáenz Avatar answered Nov 18 '22 11:11

Maic López Sáenz


git reset --hard should bring your repository back to normal, but you will lose uncommitted changes.

like image 15
Tom Macdonald Avatar answered Nov 18 '22 11:11

Tom Macdonald


If the problematic file is being added by your change you can just remove it from the index and add it again:

git reset <file> 
git add <file>
like image 10
Archias Avatar answered Nov 18 '22 12:11

Archias