git で fatal: index file corrupt2026年03月02日 13時12分40秒

git を複数の環境で使っていた。携帯メディアに保存されたレポジトリで、ファイルシステムをマウントしてそのまま使う。一つの環境で使って、戻した後に起こった。
$ git diff
error: bad index file
fatal: index file corrupt
git log は使えたが、diff を始め幾つものコマンドが使えない。

幾つか検索して Git: remote: fatal: index file corrupt, "index uses yz extension"? が良さそうだった。

$ rm .git/index
$ git reset --mixed
これでインデックスを再作成して問題が解決。