破損したGitリポジトリを修復する 質問する

破損したGitリポジトリを修復する 質問する

電源の問題により数回のハードリブート後に Git リポジトリが破損し、修復できなくなりました (前回の電源障害時にいくつかのファイルをステージングしている最中でした)。

$ git status
fatal: failed to read object 3d18855708b0f127d40c13c679559d7679228b69: Invalid argument
$ git fsck
fatal: failed to read object 24377c609184c192f3f3c1733bac7115c1080758: Invalid argument
$ git branch -a
(...works, lists branches...)
$ git checkout someotherbranch
fatal: failed to read object 3d18855708b0f127d40c13c679559d7679228b69: Invalid argument
$ git log
fatal: failed to read object 3d18855708b0f127d40c13c679559d7679228b69: Invalid argument
$ git log someotherbranch
(...works, shows commits...)

ご覧のとおり、現在のブランチはかなり壊れていて、修正できないようです。これを修復するにはどうすればよいでしょうか?

ベストアンサー1

同様の状況に対する私の解決策は、 の破損したオブジェクトのハッシュを.git/refs/heads/my-working-branch以前のコミットのハッシュ ( にあります.git/logs/HEAD) に置き換えることでした。

おすすめ記事