我不完全确定发生了什么,但由于某种原因,我的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
如何从中恢复?
答案 0 :(得分: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/*'