gpt4 book ai didi

Git ref master 现在空了,如何恢复?

转载 作者:太空狗 更新时间:2023-10-29 13:52:25 25 4
gpt4 key购买 nike

我不完全确定发生了什么,但出于某种原因,我的 git 存储库的 master 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

我该如何恢复?

最佳答案

感叹。

我喜欢 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

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

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/*'

关于Git ref master 现在空了,如何恢复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5240479/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com