简体   繁体   English

在Windows蓝屏之后恢复git repo?

[英]recovering a git repo after a Windows blue screen?

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 我只有一个蓝屏,我上个星期左右都有所有工作,但是现在该事件消失了……好了,我可以在资源管理器中看到.git文件夹,但执行git status or fsck它说这不是一个git repo ...这是关于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. 找回存储空间会很不错,因为幸运的是,该仓库拥有一个中央存储库,所以一切都很好...但是我的工作却不行,如果我一周没有做任何事情,那会怎么样...: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). 蓝屏之前回购的状态是我的工作在存储区中(我有7个旧存储区,而这是本周的工作),因为我的客户要求我修改某些存储区(因此我进行了一个存储区的存储)我所做的工作)进行了更改并推动了...在恢复存储之前几秒钟,我得到了蓝屏,然后在reebot之后,即使.git dir在其中,我也无法执行任何git命令... (我不知道它是否包含某些东西或仅仅是结构)。

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... 因此,这些文件的状态是一个干净的工作拷贝的藏匿处(因为目前要求的变化)和我的实际真正的工作是/ IS ...

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... 好吧,我一直在使用sourcetree作为前端...不知道是一天结束时是sourcetree还是蓝屏的问题..但问题是我在工作中失去了工作...

The blue screen followed by my git repository apparently getting corrupted just happened on my end. 蓝屏跟着我的git仓库明显被破坏只是发生在我的末端。 I noticed that the file .git/HEAD was empty. 我注意到文件.git / HEAD为空。 I fixed the problem by adding the following content to .git/HEAD: 我通过将以下内容添加到.git / HEAD来解决此问题:

ref: refs/heads/master

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 : 我首先备份了我的git仓库,然后按@ equivalent8的建议克隆了该仓库,但并没有全部替换,我只在.git使用了这个文件:

  • config 配置
  • FETCH_HEAD FETCH_HEAD
  • HEAD
  • index 指数
  • packed-refs 打包引用
  • sourcetreeconfig sourcetreeconfig

That allowed sourcetree to be able to open and git status to work (ie. it was again a git repo). 这使得sourcetree能够打开并且git状态能够正常工作(即,它再次是git repo)。

Then from https://stackoverflow.com/a/91795/682603 I modify the search a little like this 然后从https://stackoverflow.com/a/91795/682603修改搜索,就像这样

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 . 这样我就可以看到每个差异并逐个提交检查,如果是候选者,我复制了第一行上面的哈希,然后按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??? 但是我无法应用它们来检查每个文件,我得到了error: unrecognized input每次我执行git apply 48f711.patcherror: unrecognized input ,猜想我将需要手动复制粘贴/删除每个文件???

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM