git 仓库同步到坚果云上后损坏了

2021-04-03 22:06:19 +08:00
 EscYezi

前两天在家里的 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-pack 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 过,现在看似乎要重新考虑一下这种方案的可行性了。不知道大家有没有出现过类似的问题?

4916 次点击
所在节点    程序员
22 条回复
guochao
2021-06-09 09:55:19 +08:00
@hanssx 就是正常的 Git 托管服务啊,用 git 来推送或者拉取就好了
hanssx
2021-06-09 10:15:13 +08:00
@EscYezi 能分享一下脚本嘛,bundle 也需要手动操作的吧,我把.git 不上传应该就不会有问题了吧( 19 楼的方案)。

@guochao repo 多了一个个的都要 git push 去 pull 来的,太麻烦。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/767842

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX