Corrupted git repo, all history lost, desperate help request

88 Views Asked by At

I was managing a git repo, as I have done thousands of times in the past, using gitg. Suddenly, the app crashed (Segmentation fault (core dumped)) and the repo got corrupted. Now git status says

No commits yet

The files seem to be with the same content as the last commit I made before this got corrupted, so I could start over from here, but all the history would be lost. If I run git branch I get

fatal: Failed to resolve HEAD as a valid ref.

I have no idea how to further diagnose what is going on, nor solve it. Any help is very appreciated.

1

There are 1 best solutions below

2
On

After trying many different things, I was saved by this answer. If someone runs into a similar kind of issue, before doing anything, create a backup copy e.g. cp -r your_repo your_repo.backup and then start experimenting within your_repo. I had to recover from the backup several times before I was able to actually solve the problem.