My computer went dead and now one of my git repositories is broken. When I try to checkout master it tells me:
warning: ignoring broken ref refs/heads/master. error: Your local changes to the following files would be overwritten by checkout: com.vainolo.jdraw2d.releng.p2/pom.xml Please, commit your changes or stash them before you can switch branches. Aborting
When I execute git stash
I get:
fatal: bad revision 'HEAD' fatal: bad revision 'HEAD' fatal: Needed a single revision You do not have the initial commit yet
So... what can I do?
Update Output of git reflog
:
fatal: bad default revision 'HEAD'
Not very promising... Output of git fsck
:
error: Invalid HEAD Checking object directories: 100% (256/256), done. error: unable to unpack 59551f96b4e87a1c14293c19eb548ce6fa1f196f header error: inflateEnd: stream consistency error (no message) fatal: loose object 59551f96b4e87a1c14293c19eb548ce6fa1f196f (stored in .git/objects/59/551f96b4e87a1c14293c19eb548ce6fa1f196f) is corrupt
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:
.git/refs
still contains anything usefulgit reflog
and failing that the contents of .git/logs/refs/heads/master
or whatever branch you were on lastgit 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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With