恢复损坏的git存储库 [英] Recovering broken git repository

查看:88
本文介绍了恢复损坏的git存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的git存储库已损坏,无法访问其中的所有文件,即

 
$ git log
致命:错误的缺省修订版本'HEAD'



 
$ git status
...告诉我那个所有的文件都是新的

但是.git目录包含我的对象。

 
$ du -sh .git
34M .git



 
$ git count-objects
4151个对象,32692千字节



 
$ git --version
git version 1.6.0.4

我在错误出现之前记得的最后一件事是创建(clone --mirror)备份在安装了NFS的服务器上的存储库。但是克隆的备份库也是以同样的方式破坏的。



如何恢复我的存储库?

解决方案

克隆之外肯定有一些东西,但我知道记住这些东西是多么的困难。



你想要做的第一件事是看看.git / refs,看看里面是否有任何有效的东西(我不太乐观,因为你说那里没有似乎没有任何分支,但它值得一试)。如果存在任何有效的参考文献,您可以从 git-reflog

接下来,我将开始查看 git-fsck 。其主要目的是验证数据库中对象的连通性和有效性。根据您的回购确实发生了什么,您可能需要 - 无法访问 - 找不到。希望这些对象是完整的,所以你需要做的就是找到一些悬而未决的提交哈希来检出并重新创建分支。


My working git repository is broken, it lose track to all the files in it, i.e.

$ git log
fatal: bad default revision 'HEAD'  

$ git status  
... told me that all the files are new

However the .git directory does contain my objects.

$ du -sh .git
34M    .git

$ git count-objects
4151 objects, 32692 kilobytes

$ git --version
git version 1.6.0.4

The last thing I remember doing before it went wrong was creating (clone --mirror) a backup repository at an NFS-mounted server. However the backup repository cloned is broken the same way.

How can I restore my repository?

解决方案

There must've been something besides the clone, but I know how hard it is to remember those things.

The first thing you want to do is look in .git/refs and see if there's anything valid in there (I'm not too optimistic since you say that there don't appear to be any branches, but it's worth a shot). If any valid refs exist, you may be able to get some information from git-reflog.

Next, I would start having a look at git-fsck. Its main purpose is to verify connectivity and validity of objects in the database. Depending on what exactly has happened to your repo, you may need --unreachable or --lost-found. Hopefully the objects are intact, so all you need to do is find some dangling commit hashes to check out and recreate branches at.

这篇关于恢复损坏的git存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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