Git ref master现在空了,怎么恢复? [英] Git ref master now empty, how to recover?

查看:241
本文介绍了Git ref master现在空了,怎么恢复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我并不完全确定发生了什么,但由于某种原因,我的git存储库的主ref文件现在是空的。我们将托管在Dropbox上的存储库,所以也许它与此有关..但现在我无法从中获得。它表示:

 你的配置指定与远程的ref'master'合并,但是没有这样的ref被获取。 

Dropbox保留文件的版本,所以如果我回到以前版本的'master'它说:

 致命:对象2d154f82e59a4156a5d3ea04a0617c243ae6dc3a已损坏
致命:远程端意外挂起

我该如何恢复?

解决方案

感叹。

我喜欢Dropbox,但我绝不会推荐它用于托管Git存储库。它的同步对于单文件文件来说工作得很好,但它并没有提供安全托管Git存储库所需的分布式/远程文件系统语义。



<希望你只是在Dropbox上托管一个裸露的Git仓库。如果是这样,你应该能够凑齐来自非裸(工作)存储库的提交和引用。还应该可以手动恢复现有的存储库,但是您最终可能最终需要从其他存储库复制对象,因此您最好不要使用以下高级方式(而不是低级别并处理从其他存储库复制对象(或复制包文件并拆包它们的一部分))。

首先制作一个工作目录的独立克隆。 / p>

  git克隆文件://路径/ to / myrepo / path / to / myrepo-recovery-work 

从其他工作仓库导入裁判和对象。



<$ p $如果你有网络访问其他版本库:
cd / path / to / myrepo-recovery-work
git remote add other1 user @ machine:path / to / other / working-repo-1
git remote add other2 ssh:// user @ machine / path / to / other / working-repo-2
#等
git fetch --all


#如果您没有网络访问权限:
cd / path / to / other / working-repo-1&& #with machine-repo-1
git bundle create /path/to/other1.gitbundle --all HEAD
cd / path / to / other / working-repo-2&& #在带有working-repo-2的计算机上
git bundle create /path/to/other2.gitbundle --all HEAD
#等
#将捆绑文件传输到具有 myrepo-recovery-work
#(Dropbox可以复制捆绑包,它们只是单个文件),然后在该机器上
#:
cd / path / to / myrepo-recovery -work
git remote add other1 /path/to/transferred/other1.gitbundle
git remote add other2 /path/to/transferred/other2.gitbundle
#等
git fetch --all

然后,查看新遥控器上的所有分支并确定哪些分支应该指向提交到您的重建中央存储库。

  git log --oneline --graph --decorate --abbrev-commit  - -all 
#除了查看历史图之外,您可能还需要检查
#某些提交的内容。只需将它们作为独立的HEAD检查即可。
git分支已恢复/维护decafbad
分支已恢复/ master cafebabe
git分支已恢复/开发deadbeef
git分支已恢复/ bug-1234 8badf00d

创建并将恢复的分支(和标签)推送到一个新的裸仓库。

  git init --bare /path/to/new-central-bare-repo.git#或真正的Git托管服务! 
git remote add new /path/to/new-central-bare-repo.git
git push --tags new'refs / heads / recovered / *:refs / heads / *'


I'm not entirely sure what happened, but for some reason my git repository's master ref file is now empty. We're hosting the repository on Dropbox, so maybe it has to do with that..but now I can't pull from it. It says this:

Your configuration specifies to merge with the ref 'master' from the remote, but no such ref was fetched.

Dropbox keeps versions of files, so if I go back to the previous version of 'master' it says:

fatal: object 2d154f82e59a4156a5d3ea04a0617c243ae6dc3a is corrupted
fatal: The remote end hung up unexpectedly

How do I recover from this?

解决方案

Sigh.

I like Dropbox, but I would never recommend it for "hosting" Git repositories. Its synchronization works well enough for single-file documents, but it does not come close to providing the distributed/remote filesystem semantics that would be required for safe hosting of a Git repository.

Hopefully you are just "hosting" a bare Git repository on Dropbox. If so, you should be able to cobble together the commits and references from your non-bare (working) repositories. It should also be possible to manually recover your existing repository, but you will likely end up needing to copy objects from your other repositories anyway, so you might as well do it the following "high level" way (instead of going "low level" and dealing with copying objects from other repositories (or copying pack files and unpacking parts of them)).

Start by making an independent clone of one of your working directories.

git clone file://path/to/myrepo /path/to/myrepo-recovery-work

Import the refs and objects from your other working repositories.

# If you have network access to the other repositories:
cd /path/to/myrepo-recovery-work
git remote add other1 user@machine:path/to/other/working-repo-1
git remote add other2 ssh://user@machine/path/to/other/working-repo-2
# etc.
git fetch --all


# If you do not have network access:
cd /path/to/other/working-repo-1 &&  # on machine with working-repo-1
  git bundle create /path/to/other1.gitbundle --all HEAD
cd /path/to/other/working-repo-2 &&  # on machine with working-repo-2
  git bundle create /path/to/other2.gitbundle --all HEAD
# etc.
# Transfer the bundle files to the machine that has "myrepo-recovery-work"
# (Dropbox is OK to copy the bundles, they are just single files),
# then on that machine:
cd /path/to/myrepo-recovery-work
git remote add other1 /path/to/transferred/other1.gitbundle
git remote add other2 /path/to/transferred/other2.gitbundle
# etc.
git fetch --all

Then, look through all the branches on your new remotes and determine which branches should point to which commits for your rebuilt central repository.

git log --oneline --graph --decorate --abbrev-commit --all
# In addition to looking at the history graph, you might need to examine
# the content of certain commits. Just check them out as a detached HEADs.
git branch recovered/maintenance decafbad
git branch recovered/master cafebabe
git branch recovered/development deadbeef
git branch recovered/bug-1234 8badf00d

The create and push your recovered branches (and tags) to a new bare repository.

git init --bare /path/to/new-central-bare-repo.git # or real Git hosting service!
git remote add new /path/to/new-central-bare-repo.git
git push --tags new 'refs/heads/recovered/*:refs/heads/*'

这篇关于Git ref master现在空了,怎么恢复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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