3

我不完全确定发生了什么,但由于某种原因,我的 git 存储库的主 ref 文件现在是空的。我们在 Dropbox 上托管存储库,所以可能与此有关..但现在我无法从中提取。它是这样说的:

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

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

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

我该如何从中恢复?

4

1 回答 1

7

叹。

我喜欢 Dropbox,但我绝不会推荐它用于“托管”Git 存储库。它的同步对于单文件文档来说足够好,但它不能提供安全托管 Git 存储库所需的分布式/远程文件系统语义。

希望您只是在 Dropbox 上“托管”一个裸 Git 存储库。如果是这样,您应该能够将非裸(工作)存储库中的提交和引用拼凑在一起。也应该可以手动恢复您现有的存储库,但您可能最终需要从其他存储库中复制对象,因此您不妨按照以下“高级”方式(而不是“低级”并处理从其他存储库复制对象(或复制包文件并解包其中的一部分))。

首先对您的一个工作目录进行独立克隆。

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

从您的其他工作存储库中导入参考和对象。

# 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

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

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

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

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/*'
于 2011-03-09T05:21:39.547 回答