3

I have a bare repo cloned and need to check if the repo is broken. I tried running git status, but it says:

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

I have also tried running git gc and it returns non-zero if the repo is broken. But this takes hell of a time as repo size is big.

Any alternate approach in doing this?

Update: I have tried git fsck, and this also takes more or less same time as git gc. The repo size is almost ~16 gb :(

Muni
  • 31
  • 2
  • 1
    if by "checking the repo" you mean you want to check that all commits have valid parents, and a valid content, then I am afraid you will have to pay the cost to dig through those 16GB -- hence the time taken by `git gc` or `git fsck`. Do you have a suitable smaller scope in mind ? – LeGEC Jul 27 '21 at 07:58

2 Answers2

2

With a recent enough Git (2.30+), you can also try a git maintenance command.

Specifically: git maintenance start

If it starts successfully, the repository is not broken.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

You are probably looking for git fsck:

git fsck --verbose --full --strict
Peter Badida
  • 11,310
  • 10
  • 44
  • 90