0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

GitのPushエラーで詰んだけど、意外と簡単に解決した話

Posted at

はじめに

マジでイライラした。GitHubにpushしようとしたら見慣れないエラーが出てきやがって、何度やっても同じ結果。「あぁ、今日は徹夜コースか...」って思ったけど、意外と簡単に解決できたから共有しとく。

発生した問題

error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: the remote end hung up unexpectedly
fatal: the remote end hung up unexpectedly

みたいなクソエラーが出てきて、しかも大きいファイル追加した直後だからめっちゃ焦った。何度やっても同じエラーでpushできねぇ。

解決策

結局、以下の2つのコマンドを順番に実行したらあっさり解決した。

# リポジトリ内の不要なオブジェクトを整理して断片化を解消
git gc --prune=now

# HTTPポストバッファサイズの設定(大容量ファイルがある場合の対策)
git config http.postBuffer 524288000

なぜ解決したのか?

git gc --prune=now

これ、リポジトリ内のゴミみたいな不要オブジェクトを掃除するコマンド。Gitは差分を管理してるからどんどんゴミが溜まる。gcはガベージコレクションの略で、--prune=nowオプションは「今すぐ掃除しろよ」って命令。

断片化してたファイルが整理されて、転送がスムーズになった感じ。

git config http.postBuffer 524288000

これはHTTPでのpush時のバッファサイズを増やすコマンド。デフォルトだと100MBくらいなんだけど、これを500MBに増やしてる。大きなファイルをpushするときに「バッファ小さすぎだろ!」ってなるのを防止してる。

まとめ

ぶっちゃけ、大きいファイルをコミットした後にpushでエラー出るのはよくあること。特に画像とかバイナリファイルとか追加した時に起きがち。

今回の対処法は:

  1. ゴミを掃除 (git gc --prune=now)
  2. バッファサイズを増やす (git config http.postBuffer 524288000)

この2つでほとんどのpushエラーは解決するはず。

あと、そもそも論として大きいバイナリファイルはGit LFSを使うとかgitignoreに追加するとかした方がいいんだけど、それはまた今度書く。とりあえず今回のエラーはこれで解決!

おまけ

pushエラーでググると色々な解決策出てくるけど、個人的には上記2つが一番シンプルで効果あった。他には以下も試したけど、結局上の2つで解決した:

  • git config --global core.compression 0 (圧縮を無効化)
  • git config --global http.lowSpeedLimit 1000 (低速制限の設定)
  • git config --global http.lowSpeedTime 60 (低速制限の時間設定)

お前らも同じエラーに遭遇したら、まず上の2つを試してみてくれ。多分解決する。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?