以下エラーが出た場合の対処法
remote: Enumerating objects: 1016, done.
remote: Counting objects: 100% (1016/1016), done.
remote: Compressing objects: 100% (349/349), done.
remote: Total 1016 (delta 707), reused 904 (delta 637), pack-reused 0
Receiving objects: 100% (1016/1016), 253.71 KiB | 1.36 MiB/s, done.
Resolving deltas: 100% (707/707), completed with 64 local objects.
**fatal: bad object refs/heads/master 2**
error: XXXXXXXXXXXXX.git did not send all necessary objects
Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
**warning: The last gc run reported the following. Please correct the root cause
and remove .git/gc.log**
Automatic cleanup will not be performed until the file is removed.
fatal: bad object refs/heads/master 2
fatal: failed to run repack
// 訳
error: XXXXXXXXXXXXX.git 必要なオブジェクトをすべて送信していない
最適なパフォーマンスを得るために、バックグラウンドでリポジトリの自動パッキングを行います。
手動でのハウスキーピングについては、"git help gc" を参照してください。
警告を表示します: 最後の gc の実行で、以下のことが報告されました。根本的な原因を解決してください
を修正し、.git/gc.log を削除してください。
このファイルが削除されるまで、自動クリーンアップは実行されません。
fatal: 悪いオブジェクト refs/heads/main 2
fatal: repackの実行に失敗しました。
何やらgcがうまく動いておらず、リポジトリの最適化が出来ていないらしい
<aside> 🌿 【gc】
gc:ガベージコレクション(garbage collection)
gitで管理されている不要なファイルを掃除してくれるシステムのこと。普段は自動でやってくれるので気にする必要はないのだが、たまに上記のようなエラーが発生するらしい。
</aside>
邪魔しているものを消す
今回は以下2種が邪魔していたので消す
rm .git/refs/heads/master\\ 2
rm .git/gc.log
gcを動かす
git gc
もう一度pullを試す
git pull origin main
(git pull リモートリポジトリ名 ブランチ名)
git fetchしようとしたら fatal: bad object refs/heads/master 2 - Qiita