Git-文件夹"refs"丢失的 [英] Git - folder "refs" missing

查看:184
本文介绍了Git-文件夹"refs"丢失的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不得不从备份中恢复几个git裸存储库,并发现git(我在Windows XP上使用msysgit)无法识别该仓库.经过一番调查,我发现问题似乎在于文件夹"refs"以及子文件夹"heads"和"remotes"都丢失了.我也没有文件"heads/master".有什么办法可以重新创建它?我真的需要恢复这些文件夹中的数据.

I had to recover a few git bare repositories from a backup, and found out that git (I am using msysgit on wondows XP) did not recognise the repo as such. After some investigation, I found the problem seems to be that the folder "refs" was missing, together with the subfolders "heads" and "remotes". I also do not have the file "heads/master". Is there any way I can re-create it? I really need to recover the data in these folders.

推荐答案

当然,如果您对这些存储库有任何签出,最简单的操作就是从这些存储库中恢复.

Of course, if you have any checkouts of these repos, the easiest thing to do is to just recover from those.

refs仅包含具有这些名称所指向的提交SHA1的文件; refs/heads/master可能就是您所需要的,仅包含HEAD提交的SHA1.您没有丢失任何数据(全部在objects中),但是要找出所需提交的SHA1可能有些棘手.

refs just contains files with the SHA1 of commits that those names point to; refs/heads/master is probably all you need, containing just the SHA1 of the commit for HEAD. You didn't lose any data (that's all in objects), but it might be a bit tricky to find out the SHA1 of the commits you want.

如果有文件logs/HEAD,则引用应位于底部(第一个SHA1是最新提交的父级,第二个SHA1是其提交的ID;如果是合并,则可能会更多)提交,不确定).例如,这是我的一个回购的最后一行:

If you have the file logs/HEAD, the ref should be in there at the bottom (the first SHA1 being the parent of the most recent commit and the second being the id of it; there might be more if it's a merge commit, not sure). For example, here's the last line of one of my repos:

4b2ef6873c3f4c7eaebca06fee4b95ffa9cf58c3 feb84419b6685b920f8a3d61a77e9508ba5dcfe1 Dougal Sutherland <dougal@gmail.com> 1342838724 -0400 pull: Fast-forward

所以以feb84419b6开头的哈希是我想要的哈希.不幸的是,我认为这些只是非裸结帐.

so the hash starting with feb84419b6 is the one I'd want. Unfortunately, I think these are only in non-bare checkouts.

如果没有这些日志,则所有提交都在objects目录中.它可能是最近修改的版本,例如您可以在Unix上通过objectsobjects目录获得它.您可以尝试几个,看看会发生什么.如果您从中得到答案,请说

If you don't have those logs, the commits are all in the objects directory. It's somewhat likely to be a recently modified one, which you can get on Unix for example by ls -1t */* | head -10 from the objects directory; you can try a couple and see what happens. If you get from this, say

04/718652eb1f03bb0594cc05665665b749b52a87

然后删除/以获取要使用的哈希:

then remove the / to get the hash you want to use:

04718652eb1f03bb0594cc05665665b749b52a87

这篇关于Git-文件夹"refs"丢失的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆