My Git repository got corrupted after a couple of hard reboots due to power supply issues and now I\'m unable to fix it (I was in the middle of staging some files at the las
For me, I had enabled TRIM in OS X with a non-Apple SSD (which is not recommended) and apparently caused various corruptions on my boot disk. So the corrupted commit was deep in the history.
I don't care too much about repairing my repository, except I have a few local branches that were too experimental to bother pushing to the remote repository, and I'd like to salvage the work in those branches.
Theoretically, since this is a local repository, I feel that Git should be able to recover/repair itself using origin. Why isn't this possible?
At any rate I stumbled across this cool strategy to push a branch to another local Git repository. Unfortunately, cloning the repository into ../repo_copy
and then using that as a local remote resulted in the following error:
! git push --force local_remote HEAD
fatal: failed to read object e0a9dffddeeca96dbaa275636f8e8f5d4866e0ed: Invalid argument
error: failed to push some refs to '/Users/steve/Dev/repo_copy'
So I started instead with an empty repository, and then pushing branches to it worked OK. So for any local branch I had whose git log
didn't end in:
....
Fixing cukes
fatal: failed to read object e0a9dffddeeca96dbaa275636f8e8f5d4866e0ed: Invalid argument
I simply would check it out and then do git push --force local_remote HEAD
. The last thing I did was:
! cd ~/Dev/repo_copy
! git remote add origin git@github.com:sdhull/my_repo.git # real remote
Then I went in to git config -e
and set up my master branch and was back up and running with nothing lost!
I had the same problem and did the following steps using git-repair
cp myrepo myrepo.bak
cd myrepo
git repair --force
(first try it without force
)After this was successful the tree was set back to the last working commit.
Then I did meld myrepo myrepo.bak
to apply changes from the working tree of the corrupted repository to the fixed repository.
This just happened to me. I reclone the repository in a new folder and move my latest changes over manually. Low tech, but it works every time. Hopefully you can remember your last changes.