1

I just got a blue screen, I have all my work of the last week or so in the stash, but now after that event it is gone... well, I can see the .git folder in explorer but doing git status or fsck it says it is not a git repo... here is a little play on powershell

PS C:\Users\tyoc\Documentos\wtf> git status fatal: Not a git repository (or any of the parent directories): .git PS C:\Users\tyoc\Documentos\wtf> cd .git PS C:\Users\tyoc\Documentos\wtf\.git> git status fatal: Not a git repository (or any of the parent directories): .git PS C:\Users\tyoc\Documentos\wtf\.git> cd .. PS C:\Users\tyoc\Documentos\wtf> git init Reinitialized existing Git repository in C:/Users/tyoc/Documentos/wtf/.git/ PS C:\Users\tyoc\Documentos\wtf> git status fatal: Not a git repository (or any of the parent directories): .git PS C:\Users\tyoc\Documentos\wtf> git fsck --no-reflog fatal: Not a git repository (or any of the parent directories): .git PS C:\Users\tyoc\Documentos\wtf> git stash fatal: Not a git repository (or any of the parent directories): .git

It will be nice to get the stash back, because by fortune the repo has a central repository, so all is OK there... but my work is not, how is like if I havent made anything for a week... :S.


I add this for clarification:

The state of the repo before the blue screen was that my work was on the stash (I have like 7 old stashes and this last was my work in the week), because my client requested me to modify something (so I make a stash of what I was working on) did the change and pushed... some seconds before I did restore the stash I got the blue screen, then after reebot, Im unable to do any git command even the .git dir is in there... (I dont know if it contains something or is only the structure).

So, the state of the files was a clean working copy (because the change requested at the moment) and my actual-real-work was/IS on the stash...

And well I was using sourcetree as front end... dont know if is the fault of sourcetree or the bluescreen at the end of the day.. but the thing it is that I lost my job in the stash...

tyoc213
  • 1,223
  • 18
  • 21
  • 1
    why don't you just clone the git repo to a fresh new folder and just copy the files you changed there(your work). – equivalent8 Nov 07 '17 at 09:53
  • 1
    ....or other way around remove the old `.git` folder , clone repo to new folder and just copy the `.git` folder to your old folder – equivalent8 Nov 07 '17 at 09:55
  • Because the work I want to recover was on the stash of the damaged repo... – tyoc213 Nov 07 '17 at 09:59
  • oh that's bad,really really bad, sorry I have no idea how to fix that. I know it's not helpful but: git is good at commits as they are distributed between multiple machines (basically every machine with git repo is a full repo) and therefore always recoverable, `git stash` is single machine and equivalent of storing on single source of truth. I hope someone else will write you some more helpful answer. – equivalent8 Nov 07 '17 at 13:12
  • thx I fixed it somewhat with your suguestions, I have annotated what I do and therefore will write the extended answer... thought I ended with not aplicable patches... I guess I will need to merge them manually... best than have nothing... – tyoc213 Nov 08 '17 at 04:48

2 Answers2

4

The blue screen followed by my git repository apparently getting corrupted just happened on my end. I noticed that the file .git/HEAD was empty. I fixed the problem by adding the following content to .git/HEAD:

ref: refs/heads/master
Paulo Barros
  • 2,740
  • 8
  • 28
  • 36
  • 1
    After doing this, I got `error: bad signature` and `fatal: index file corrupt`. I then followed the instructions in https://stackoverflow.com/a/1115956/5536 and am back in business. – Paul Stephenson Apr 29 '19 at 13:55
0

I made a backup of my trashed git repo first, then I cloned the repo as suguested by @equivalent8 but did not replace it all, I only used this files inside .git:

  • config
  • FETCH_HEAD
  • HEAD
  • index
  • packed-refs
  • sourcetreeconfig

That allowed sourcetree to be able to open and git status to work (ie. it was again a git repo).

Then from https://stackoverflow.com/a/91795/682603 I modify the search a little like this

git fsck --no-reflog | select-string 'dangling commit' | foreach { $bits = $_ -split ' '; echo $bits[2]; git show $bits[2]}

SO that I can see each diff and inspected commit by commit, if it was a candidate I copied the hash that is above on the first lines, and advanced to the next mach pressing q.

Then for each candidate I did do

git diff 52abca5cba3ff37b4954fd2c2e12c867dceb9481 --color=never > 52abca.patch git diff 48f7110fa9d507226ce31593a0fc957e465d6c91 --color=never > 48f711.patch

SO that I dont lost them again, and checked the candidates, my work was still there!!! (I think)

But I can't apply them to check each one, I got error: unrecognized input each time I do git apply 48f711.patch, guess I will need to copy paste/delete each file by hand???

tyoc213
  • 1,223
  • 18
  • 21