Rebuild loose missing tree in Git when there are n

2019-08-13 19:24发布

问题:

My Git repository claims there is a corrupted object: running git fsck --full says that there's a corrupted loose object in the repo. Since the object is corrupted, I can't unpack it using git cat-file -t, but removing the file causes fsck to report only:

broken link from tree 93e54230ef...
            to tree 5aec4ad...
missing tree 5aec4ad...

I think this missing tree is the only file that is missing, or rather that there are no dangling commits/blobs, because running git ls-tree 93e54230ef... shows only one line: 040000 tree 5aec4ad... android. Also, the last-modified date on the corrupted file is yesterday, and I haven't made any changes since then. Unfortunately, I've checked the clones I have of this repository, but none of them have the missing object packed or unpacked.

How can I rebuild a missing git tree with no dangling commits or blobs?

回答1:

When all that is missing in Git is a tree, the solution is simply to use write-tree:

git write-tree

After executing that command, the Git repository should revert to its previous state.