Search code examples
gitcorruption

git repo corrupted, unable to status with: "BUG: fsmonitor.c:21: fsmonitor_dirty has more entries than the index"


First indication of issue:

❯ git rebase -r master
BUG: fsmonitor.c:21: fsmonitor_dirty has more entries than the index (179457 > 1040)
zsh: abort      git rebase -r master

Got "stuck" in this state, not sure how to recover or repro:

❯ git status
BUG: fsmonitor.c:21: fsmonitor_dirty has more entries than the index (179457 > 1040)
error: git died of signal 6

❯ git log  # works

❯ git diff head~
error: git died of signal 6
BUG: fsmonitor.c:21: fsmonitor_dirty has more entries than the index (179457 > 1040)

❯ git diff head~..head~~  # works

❯ git checkout head
BUG: fsmonitor.c:21: fsmonitor_dirty has more entries than the index (179457 > 1040)
zsh: abort      git checkout head

Solution

  • Turns out git's index got corrupted during the rebase.

    From: https://git.seveas.net/repairing-and-recovering-broken-git-repositories.html

    mkdir .git/my_backup
    mv .git/sharedindex.* .git/my_backup
    mv .git/index .git/my_backup
    git reset --mixed  # rebuild index
    

    updates:

    likely related git mailing list threads:

    Suspected culprit is setting config core.splitIndex along with core.fsmonitor (and/or possibly feature.manyFiles).

    Though it may have been fixed in 2.4.1: https://github.com/git/git/commit/3704fed5eae8ca2fa20bcf6adb277ee83b012ce0