"Not a git repository" after OS reset

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:

  1. .git/HEAD (set content to ref: refs/heads/master)
  2. $> git branch -v (this will tell you all the corrupt branches)
  3. .git/logs/HEAD (Read the file for last checksum of the commits and merge of corrupt branches)
  4. .git/refs/heads/{corrupt branch file} (change the checksum to the last working checksum from the log file.
  5. merge the branches again as per need.

Tags:

Windows

Git