Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error building trees error prevents committing to branch

I have a local git repository on my Mac that is managed by Xcode. I recently created a new branch and have made a lot of changes since then. I was about to perform my first commit to this new branch and was presented with an error dialog:

The working copy "app name" failed to commit files.
error: invalid object 100644
888688965... for 'Supporting Files/animage.png'
error: Error building trees

I searched the Interwebs for a solution and found this question which appears to be the same issue. I tried both answers to this question and neither solved the problem for me. I have done everything I can think of to solve the problem but have not been successful.

  • I tried looking for the problematic file as the answer suggested but there are no files in /repo/.git/objects/88. I also looked in backups (I have hourly Time Machine backups) but there never were files in that folder.
  • I tried git reset --hard and this removed uncommitted changes, but after doing so I cannot commit a simple change. The exact same error message is presented.
  • I tried to trash the image referenced in the error message, but then the next time I attempt to commit the same error is displayed referencing a different image. After trashing all images it started listing code files.
  • I tried creating a new branch and committing to that branch, but the same error is presented.
  • I switched to my other partition where I previously worked on this project (the files sync over Dropbox which may have been the cause of the problem) and attempted a commit only to experience the same error message.
  • I finally decided to restore the entire project to an earlier point in time, I went back two months ago before I even made any branches, yet still a simple commit refuses to work. This makes me believe an external factor is involved, something outside of the project folder. I know it worked back then so this has me very confused. This is the error presented:

The working copy "app name" failed to commit files.
fatal: unable to read tree 781d...

After running git fsck --full I see there are several broken links from trees, a lot of dangling blobs, several missing blobs, and two missing trees.

The result of git for-each-ref --format='%(refname)' | while read ref; do git rev-list --objects $ref >/dev/null || echo "in $ref"; done:
fatal: missing blob object '8886889658056c4ce52d46a485933c8df7a4de84'
in refs/heads/UniversalStoryboard
fatal: missing blob object '8886889658056c4ce52d46a485933c8df7a4de84'
in refs/heads/Update1
fatal: missing blob object '8886889658056c4ce52d46a485933c8df7a4de84'
in refs/heads/iOS-8-Update
fatal: missing blob object '8886889658056c4ce52d46a485933c8df7a4de84'
in refs/heads/master

After attempting to clone the repo, this is what is logged:
error: unable to read sha1 file of appname/Images.xcassets/AppIcon.appiconset/Icon-Small-1.png (86672e7aa0d5ad36563feef30c15a5d31f921802)
error: unable to read sha1 file of appname/Images.xcassets/AppIcon.appiconset/Icon-Small.png (86672e7aa0d5ad36563feef30c15a5d31f921802)
error: unable to read sha1 file of appname/Images.xcassets/LaunchImage.launchimage/[email protected] (7d97eba35cf392ddb1a705109b721fcd6a20ea29)
error: unable to read sha1 file of appname/appname-Prefix.pch (82a2bb45076d290ce7461b28d5a579e649777779)
fatal: unable to checkout working tree
warning: Clone succeeded, but checkout failed.

At this point in time I am willing to do anything to prevent having to trash the entire git repository and start over. I don't want to lose my branches and history. How can I fix this issue? I have a working copy of the project directory exactly as it was when I first discovered the error as well as Time Machine backups for the entire history of this project. Anything you can suggest is appreciated.

like image 234
Jordan H Avatar asked Nov 01 '22 19:11

Jordan H


1 Answers

One fix is to:

  • revert to command line.
  • clone your current repo
  • try and create new branch/new commit on that clone.

If you had previously pushed your repo, try cloning the remote repo instead of the local one.
Or try cloning the repo as save by Time machine.

If that doesn't work, you have a broken repo, and you can try some of the methods exposed in "Tree contains duplicate file entries".

like image 56
VonC Avatar answered Nov 09 '22 08:11

VonC