Search code examples
gitgit-indexgit-fsck

How can I recover from "invalid sha1 pointer in resolve-undo" with git fsck?


I run git gc in a repository and get a fatal error:

Enumerating objects: 2382, done.
Counting objects: 100% (2382/2382), done.
Delta compression using up to 8 threads
Compressing objects: 100% (747/747), done.
fatal: unable to read <object-id>
fatal: failed to run repack

Running git fsck --full --no-dangling provides more detail about the problem with that object:

Checking object directories: 100% (256/256), done.
Checking objects: 100% (2381/2381), done.
error: <object-id>: invalid sha1 pointer in resolve-undo
Verifying commits in commit graph: 100% (287/287), done.

I believe this is caused by a bug that has been fixed:

The resolve-undo information in the index was not protected against GC, which has been corrected with Git 2.38 (Q3 2022).

If my repository is already in this state, how can I fix it?


Solution

  • Ensure you don't have any staged changes and recreate the index.

    rm .git/index
    git reset
    

    This will recreate the index from HEAD without including the resolve-undo extension.