This morning my Windows 10 crashed and rebooted once I lifted my laptop's screen. No special activity was progressing, so I don't think there was significant disk activity.
However one of my main Git repos crashed after that reset. Here is what I tried:
$ git status
fatal: Not a git repository (or any of the parent directories): .git$ git init
Reinitialized existing Git repository in ....../.git/$ git status
fatal: Not a git repository (or any of the parent directories): .gitI don't think I have unpushed commits, so wiping and cloning from remote should work.
Still, can I ask what to do to recover an existing Git repository (.git
directory still exists, chkdsk
reports OK) in such cases?
[Add] read this but did not apply to my case (I can't restore the repo)
As kabanus said in a comment, you should definitely save whatever you can before proceeding (and/or use some other existing clone as a backup).
When Git complains about this, though, it often means that the file .git/HEAD
has gone missing. If you create a new HEAD
file with contents: ref: refs/heads/master
, Git may be able to recover everything.
Since HEAD
is the most active file in the repository, it's the one most likely to be clobbered by an OS error or power failure. It's also a critical file when it comes to whether Git believes a .git
directory is a repository: if the directory contains a file named HEAD
(along with a few other key items), it is a repository; if not, it is not a repository.
I had multiple branches corrupt due to OS error (bloody windows sleep function!!). So I had to manually do the following:
ref: refs/heads/master
)$> git branch -v
(this will tell you all the corrupt branches)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