技术解析
前两天在家里的 windows 笔记本上git init --bare
新建了一个仓库,然后把这个文件夹同步到了坚果云上,并且向这个仓库里 push 了一些代码。
昨天在公司的 mac 上用坚果云把这个文件夹同步下来然后git clone
到本地,并向仓库 push 了一些代码,看坚果云同步结束合上电脑下班了。到这里为止都没发现什么异常。
今天在家用坚果云把仓库同步下来,本地 pull 发现报错了,具体错误信息没有记录下来,换了一个目录 clone 报错
D:\projects>git clone file:///D:/nutstore-sync/git/algorithm al2 -b main
Cloning into 'al2'...
remote: errorerror: git upload-pack: git-pack-objects died with error.
fatal: git upload-pack: aborting due to possible repository corruption on the remote side.
: Could not read 757adde25527ab466f2d48f3ae71ca1464b6df1ffatal: early EOF
remote: fatal: Failed to traverse parents of commit d26c516d98ef670e228eae36363bd015056b1283
remote: aborting due to possible repository corruption on the remote side.
fatal: fetch-pack: invalid index-p大带宽服务器ack output
进到仓库里fsck
了一下
D:\nutstore-sync\git\algorithm>git fsck --name-object
Checking object directories: 100% (256/256), done.
broken link from commit d26c516d98ef670e228eae36363bd015056b1283 (refs/heads/main)
to commit 757adde25527ab466f2d48f3ae71ca1464b6df1f (refs/heads/main^)
broken link from tree 07e1bf67bee247eb4db40fa135f705dd05fa8972 (refs/heads/main:src/xxx/xxxxx/algorithm/)
to tree 8e30aad2ed2800aeed6c801b4b94d8847deb323a (refs/heads/main:src/xxx/xxxxx/algorithm/foroffer/)
missing tree 8e30aad2ed2800aeed6c801b4b94d8847deb323a (refs/heads/main:src/xxx/xxxxx/algorithm/foroffer/)
dangling tree 0f705bbff03e60514e46a060c4d61684582a55db
dangling blob 39408c376bd54f576a653b79fd899f37452fe4af
dangling tree cf04f6b34931f215f460332cbd0029669b9c60da
dangling tree e3170836338f688d7bd1d12f85cde4ec7705cf6d
dangling commit f1180ef1b7f4e924ecfbfd71bf05f0cea5c53367
missing commit 757adde25527ab466f2d48f3ae71ca1464b6df1f (refs/heads/main^)
搜了半天,找到的恢复方法都是先要有一个完整的仓库,在此基础上对损坏的仓库进行修复。但是现在的情况相当于远程仓库损坏了,有最新提交的本地仓库又在公司的电脑上,想着也没多少修改,干脆把代码提到了 GitHub 上,以后直接从 GitHub 拉代码总不会出问题了吧。
有趣的是在搜索解决方案的时候发现了一段话:
This isn't much help but: do not store Git repos in Dropbox or any other sync services. Git isn't built to handle another program randomly locking and rewriting files while it's doing something else.
之前也有过把 git 仓库放在 OneDrive 上,不过只是 push,没有从上面 clone 过,也没有同步到多端 push 和 clone 过,现在看似乎要重新考虑一下这种方案的可行性了。不知道大家有没有出现过类似的问题?