Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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): .git
  • Loop

I 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)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
632 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...