0

We have the following situation: one of our developers has just committed some important changes into a local branch, and then she has checked out another branch. The computer crashed and now, when running 'git status' in the project directory we receive the error "fatal: Not a git repository (or any of the parent directories): .git". We've made sure the .git repository is at fault (we've scanned the disks, we've reinstalled git, we've cloned the repository from the server into another folder and then copied the unrecognized .git folder over the clone, we've tried to run git fsck and we receive the same error). How can we repair that git repository (we really need to recover the changes she just made)?

Dan
  • 1,927
  • 2
  • 24
  • 35
  • 1
    First, does the duplicate link solve your problem? – Lasse V. Karlsen Apr 21 '17 at 10:05
  • 1
    Secondly, you can try something else. Make a fresh clone and then copy the .git\objects folder from the broken repository into it, making sure only to copy files that doesn't exist (you may have to use a different tool than simply copy). Then run `git fsck` and make a note of all the dangling commits that are listed, then do a `git cat-file -p SHA-of-commit` and find the end-point, then create a branch on that commit with `git checkout SHA-of-commit & git branch lost-and-found`. Finally execute another `git fsck` to verify everything looks good. – Lasse V. Karlsen Apr 21 '17 at 10:05
  • @LasseV.Karlsen: thank you for your suggestion; we didn't follow it because we manage to recover the unpushed changes by manually editing the HEAD file and then by another unexpected reset of the machine (I cannot explain how this solved the problem, simply editing the HEAD file did not fix it; the machine reset after editing the HEAD file did it). I'll try it on the broken repository in a few days, when hopefully I'll have more time for it. – Dan Apr 21 '17 at 11:18
  • So you had an unexpected system crash which brought you here, and you had another unexpected system crash that together with the modifications to HEAD seemingly fixed the problem. I'm **hoping** that one of the steps to clean up this mess involves "chuck that computer out the window"? – Lasse V. Karlsen Apr 21 '17 at 12:36
  • @LasseV.Karlsen: Well, the "crash" was actually "power outage"; I've cooled down enough now to actually have a good talk with my manager about purchasing UPS-es for all PC-s in the office we've just moved in. It was not the poor PC fault, but really bad weather in my area that knocked off some utilities poles. – Dan Apr 21 '17 at 14:30

0 Answers0