Reputation: 95
I turned my computer off after putting in to sleep and discovered it was a hard reset, not sleep. My git repo got broken. Fortunately, I've committed and pushed everything so I just need to reset it to a pristine state. Here is what I get when I run git fsck --full
$ git fsck --full
error: Invalid HEAD
error: inflate: data stream error (unknown compression method)
error: unable to unpack 0485493a56ad42802b72cee71522666628294e3d header
error: inflate: data stream error (unknown compression method)
fatal: loose object 0485493a56ad42802b72cee71522666628294e3d (stored in .git/objects/04/85493a56ad42802b72cee71522666628294e3d) is corrupt
I was on betterfmgr
branch but the .git/refs/heads/betterfmgr
is an empty file. Any idea how to fix it? I could just clone it again but I need to copy zillion of node_modules
and copy over my .idea
files.
Upvotes: 1
Views: 1933
Reputation: 51780
You can try the following : get a fresh and sane copy of the .git/
directory from a new clone of the remote repository
I will try to illustrate the idea :
git clone sources_server:repo newdir/ # make a git clone, in a new directory
cd newdir/
git checkout betterfmgr # set active branch to 'betterfmgr'
cd ..
cd olddir/ # go into your original working copy,
# with current node_modules/ dir, .idea files, etc ...
mv .git/ .git.old/
mv ../newdir/.git .git # get ".git/" folder from other repository
# now check if everything looks like you expected :
git status ...
git diff ...
git difftool -d ...
idea ...
# if all looks well, remove old dir :
rm -rf .git.old
Note that this will loose your local branches and your reflog, though.
Upvotes: 2
Reputation: 5981
If you pushed everything as you said it, just make a git clone in another directory and delete the broken repo.
Upvotes: 2