2

如何获得一个干净的 git 存储库?这可能是失去了一些历史,但不是全部。此存储库可能已被SyncThing工具(一种用于在机器中同步文件的工具)的并发修改和无效合并损坏。

在每个git commit

...
Could not read e7ac6796b130b61f0f382b0d31845239eeb61e6e
fatal: Failed to traverse parents of commit b5e5b4601495191a5700bcba4e2227515db77376
fatal: failed to run repack
...

git fsck --full

Checking object directories: 100% (256/256), done.
Checking objects: 100% (26828/26828), done.
broken link from  commit b5e5b4601495191a5700bcba4e2227515db77376
              to  commit e7ac6796b130b61f0f382b0d31845239eeb61e6e
broken link from    tree f2678f1595a2eebd798afb9496614a09eb75d1b6
              to    tree ecd48fc55a31781d2b4cbad0629c10590de0b1a5
broken link from    tree 1259b1ca62274228c9c42aaf4a9a2276a5b60a32
              to    blob 00162d2c6425ae3166187089ff2724cb2bce23db
dangling commit f5079404103ce1343d46884219cbea7d73d0e849
dangling blob b03a78f393908690b5a395b2842c2d99b1d185e7
dangling blob 134bba35a1bda0ed2c4e57640738d8d0e999e483
dangling blob 1180e69eaaa1915c12a4c1d77b20bbc08ad60633
dangling commit f39624880f4f97131d1d56deb7a3ba5289186015
dangling commit 27d46e5a9fc0d28eb7b5229cb9ca06cbf1d6d065
missing blob 00162d2c6425ae3166187089ff2724cb2bce23db
dangling commit 5e2a2d64abce8e24e83f1d5c59f096b6c7180959
dangling commit 273b659b039d66014957dbe1fa3eb975e80b9d03
dangling commit 084d6f70f7b72e1ee4bfd181ec00f8840b9abe7a
dangling commit 5657bf6382d23a2c216af7364612ef73931ad88a
dangling blob cb6bd151bdfe88348d248437b8ddb77eb4669cab
dangling blob aa7ea55c9a797f1ccb1285c1a2fdf81c7fbcacf5
missing commit e7ac6796b130b61f0f382b0d31845239eeb61e6e
missing tree ecd48fc55a31781d2b4cbad0629c10590de0b1a5
dangling commit f1f62b99255d06356be53666bfac72a67b93f264

git gc

error: Could not read e7ac6796b130b61f0f382b0d31845239eeb61e6e
fatal: Failed to traverse parents of commit b5e5b4601495191a5700bcba4e2227515db77376
fatal: failed to run repack

尝试克隆此存储库:

> git init 
> git remote add parent <mypath to the broken repo>
... 
> git pull parent master
remote: error: Could not read e7ac6796b130b61f0f382b0d31845239eeb61e6e
remote: fatal: Failed to traverse parents of commit b5e5b4601495191a5700bcba4e2227515db77376
error: git upload-pack: git-pack-objects died with error.
fatal: git upload-pack: aborting due to possible repository corruption on the remote side.
remote: aborting due to possible repository corruption on the remote side.
fatal: protocol error: bad pack header

git 版本 2.25.1

4

2 回答 2

2

最好:

话虽如此,正如我之前提到的,使用 git bundle 会更安全。

OP Artyom在评论中更喜欢基于存档的选项:

tar --exclude-from=$backupexcludefile \
      --xattrs --create --preserve-permissions --file - ~ | \
    7za a -si -mx=3 $backupfile

这个想法保持不变:只同步一个文件。

于 2020-03-14T09:23:20.670 回答
1

我设法替换了损坏的提交链接的父级,如下所示。它现在运行git loggit blame以及其他使用替换的。但git fsck仍然显示错误。尽管如此,我现在可以在这个程度上使用 git。我在这篇文章中找到了这个建议。

所以首先我检查了所有悬空提交的日期:

git show <my dangling commits shas>

然后我用最早的替换了损坏的提交的父级:

git replace --graft b5e5b4601495191a5700bcba4e2227515db77376 f1f62b99255d06356be53666bfac72a67b93f264
于 2021-12-22T13:18:31.773 回答