Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git push fails to github: failed to read object

The story:

I've been developing a RoR-app in both my desktop and laptop. It was quite handy to commit changes made on another, push them to github and fetch & merge on other.

The starting point is this: I committed latest changes on my desktop, pushed them to github and then fetched and merged them into my laptop. Then, I made some commits on laptop and pushed to github. Took the changes, merged to my desktop (with --no-ff). THEN, happened the probable source of all mischiefs: I reverted the desktop to commit where it was before the latest fetch & merge. Made some development work with it, committed, pushed to github. In the laptop, I did the revert as well, though I reverted it to a commit which was made somewhere between the latest fetch from github, fetched again and merged those. Some error messages came after reverting desktop and laptop both, but things worked still fairly well and I kept working on both machines.

Until now. I tried to push from my laptop to github, which gives the following output:

 Counting objects: 106, done.
 error: unable to find 5a2a4ac...
 error: unable to find bc36923...
 error: unable to find ecb0d86... 
 error: unable to find f76d194...
 error: unable to find f899df7...
 Compressing objects: 100% (64/64), done.
 fatal: failed to read object 5a2a4ac... : Invalid argument
 error: failed to push some refs to 'git@github:username/repo.git'

So, the question is, what exactly took place here?

EDIT: It seems that because of suspending my laptop and moving it from place to place in that state screwed up the hard drive somehow. The fsck output is unavailable because we worked around the problem and kept on working, but IIRC some branches and commits were dangling, including that commit which git failed to read. - Teemu

like image 783
Teemu Vainio Avatar asked Sep 21 '11 00:09

Teemu Vainio


2 Answers

I have run into these kinds of issues.

Rather than spending hours trying to resolve and fix these issues, my 'solution' is usually to take the code I want, copy it into a new directory, delete the .git files and then create a new github for it and then connect the two as usual.

Although this may not be a specific answer to the details you raise, I find that there can be a number of ways that git/github issues can happen and rather than wishing I was a 'git expert' now (it's happening but it takes time), I do the above and continue with my actual application development.

like image 145
Michael Durrant Avatar answered Oct 14 '22 09:10

Michael Durrant


The problem you have is that you are trying to read objects that are not part of your 'tree'. They exist but they have been orphaned. However, git allows you to merge one project to another so this is one way you can keep your commits without starting again, something like the following:

  1. git remote add -f somename git://somegitplace.com/user/some.git

  2. git merge -s ours --no-commit somename/master

  3. git read-tree --prefix=ext/somename -u somename/master

  4. git commit -m 'external merge'

  5. git pull -s subtree somename master

Hope that helps. Let me know if not and we can attack it again

like image 40
Lloyd Moore Avatar answered Oct 14 '22 07:10

Lloyd Moore