如何在 git 中检查裸仓库的状态

问题描述

我克隆了一个裸仓库,需要检查仓库是否损坏。我尝试运行 git status,但它说:

fatal: this operation must be run in a work tree. 

我也试过运行 git gc,如果 repo 损坏,它返回非零值。但这需要很长时间,因为回购规模很大。

这样做有什么替代方法吗?

更新:我已经尝试过 git fsck,这也或多或少与 git gc 花费相同的时间。存储库大小几乎约为 16 GB :(

解决方法

您可能正在寻找git fsck

git fsck --verbose --full --strict
,

使用 recent enough Git (2.30+),您还可以尝试使用 git maintenance command

特别是:git maintenance start

如果启动成功,说明仓库没有损坏。