Git repository broken after computer died
I managed to recover through:
rm .git/refs/remotes/origin/HEAD
git fetch --all
Start by following the steps suggested in Recovering broken git repository:
- check whether
.git/refs
still contains anything useful - check
git reflog
and failing that the contents of.git/logs/refs/heads/master
or whatever branch you were on last - run
git fsck
, potentially with--unreachable
or--lost-found
This will hopefully allow you to figure out what the master
ref should be so you can restore it (i.e. cat the correct SHA1 into .git/refs/heads/master
).
In case any object contained in that commit is genuinely corrupted you can't restore your HEAD
commit unfortunately. Assuming your working tree and/or index are intact you can try a git reset --soft
(or failing that a git reset
) to the previous commit and then re-do the commit. Avoid any operations that change your working tree s.a. git checkout -f
or git reset --hard
.
I had a similar issue following a blue screen of death on windows 8.1
I had a file in this location...
C:\www\<project>\.git\refs\remotes\origin\<problem-branch>
And it was empty whereas the other branch files in this folder has long strings inside of them.
NB I didn't have any changes/commits
- I backed up the
<problem-branch>
file - Deleted the file
-
git fetch --all
to get the branch again
Then the tab auto completion started working again
If there is not many modified files, I think the convient way to solve this problem is:
- backup the files you modified in the repo
- remove your existing repo
- re-clone it from server
- paste the files from step 1 to the repo, and
git commit -a