Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

.git/indexが壊れたときの対処法

Posted at

soucetree上でブランチを切り替えようと思ったらエラーが発生してどのブランチにも移動できなくなってしまった

エラー文

'git status' failed with code 128:'error: bad signature
fatal: index file corrupt

index fileが破損しているようだ。

$ git status
error: bad signature
fatal: index file corrupt

ターミナルでも同様のエラーを確認

解決方法

  1. indexファイルを削除する
  2. git resetで前の状態に戻す
$ rm .git/index
$ git reset

It took 4.00 seconds to enumerate unstaged changes after reset.  You can
use '--quiet' to avoid this.  Set the config setting reset.quiet to true
to make this the default.

再度git statusで確認

$ git status 
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean 

これで無事にブランチを切り替えられるようになりました

まとめ

なぜ.git/indexが破損したのかは不明だが、一旦削除し元に戻すことで解決できた。

参考

Gitリポジトリのインデックスが壊れたら
【Git入門】resetでコミットを取り消す方法を解説!

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up

Comments

No comments

Let's comment your feelings that are more than good

4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?