LoginSignup
3
0

More than 3 years have passed since last update.

`git pull` した際に"reference broken"というエラーが出たときの対処法

Last updated at Posted at 2021-02-28

発生した事象

コードをgit pullしようとしたところ、

error: cannot lock ref 'refs/remotes/main': unable to resolve reference 'refs/remotes/main': reference broken

という旨のエラーが出て失敗するようになってしまいました。

当該ファイル(.git/refs/remotes/main)を覗いてみたところ、40文字ほどのNULL文字が羅列されているだけの内容でした。

発生した環境はWindows 10 (64bit)およびgit version 2.30.1.windows.1です。

解決法

Googleで検索を掛けたところ、こちら

On my system (Windows 7 64-bit), when a BSOD happens, some of the stored reference files (most likely currently opened/being written into when BSOD happened) are overwritten with NULL characters (ASCII 0).

As others mentioned, to fix it, it's enough to just delete those invalid reference files and re-fetch or re-pull the repository.

と、自分と同様の事象と解決策の報告がありました。

この報告に従い、当該ファイルを削除して再度 git pullしたところ、無事にpullすることができました。

原因

詳細な発生原因は現状では不明ですが、上記の報告でもブルースクリーンが出た後に発生したという記述があり、自分もPCがフリーズして電源を落とした後に発生しました。
Gitが何らかの作業を行っている最中にシステムがクラッシュしたことが原因の可能性が高そうです。

参考資料

3
0
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
3
0