叹。
我喜欢 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/*'