Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
656 views
in Technique[技术] by (71.8m points)

windows - "Not a git repository" after OS reset

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...