17

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

Mark Fisher
  • 965
  • 1
  • 11
  • 30
Teemu Vainio
  • 171
  • 1
  • 4
  • 6
    What does `git fsck` report? – Greg Hewgill Sep 21 '11 at 00:38
  • 1
    Maybe this one helps: http://stackoverflow.com/questions/801577/how-to-recover-git-objects-damaged-by-hard-disk-failure – tobiasbayer Oct 01 '11 at 21:01
  • What do you mean "revert"? "Reverting" in the sense of `git revert` is making a *new* commit that undoes some other commit(s), but leaves the complete history intact. If you want specific help with this, provide the actual sequence of commands that you executed at both sites. If you screwed with history that you had already pushed to your github repo, there's your oops. See http://progit.org/book/ch3-6.html#the_perils_of_rebasing . – rlibby Oct 31 '11 at 08:56

2 Answers2

5

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.

Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
  • Agreed, it's much easier, sometimes I even think about creating some simple script for it. – cnd Nov 14 '11 at 19:42
  • This is the best approach! If you commit regularly to the remote repo then it's not as tough to have something break locally. – Matt De Leon Dec 06 '11 at 19:59
1

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

Lloyd Moore
  • 3,117
  • 1
  • 32
  • 32