LoginSignup
2
3

GitでCloneしたらearly EOF

Posted at

再現手順

ReactのデザインテンプレートであるAdminLTE
自分のGitにforkし、ローカルにcloneしようとしたところ以下のエラーが出た。

% git clone {リモートリポジトリURL}
Cloning into '{リポジトリ名}'...
remote: Enumerating objects: 2889, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (3/3), done.
Receiving objects:  47% (1360/2889), 9.61 MiB | 121.00 KiB/s


error: RPC failed; curl 92 HTTP/2 stream 5 was not closed cleanly: CANCEL (err 8)
error: 7152 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output

エラーの原因

こちらはリポジトリが大きすぎる際、cloneしようとすると
「デカすぎてムリィ…」とリクエストの過負荷で怒られてしまうことが原因。

解決方法

今回は、1度でcloneするのではなく、何回かに分けてcloneするという方法を採用。

コマンドは「git clone --depth」と「git fetch --unshallow」を使う。

git clone --depth 1 {リポジトリ名}
Cloning into '{リポジトリ名}'...
remote: Enumerating objects: 1135, done.
remote: Counting objects: 100% (1135/1135), done.
remote: Compressing objects: 100% (874/874), done.
remote: Total 1135 (delta 252), reused 1040 (delta 223), pack-reused 0
Receiving objects: 100% (1135/1135), 8.77 MiB | 160.00 KiB/s, done.
Resolving deltas: 100% (252/252), done.

cloneに成功したら、そのリポジトリへ移動し、fetchする。

% cd {cloneしたリポジトリ} 
% git fetch --unshallow
remote: Enumerating objects: 1867, done.
remote: Counting objects: 100% (1867/1867), done.
remote: Compressing objects: 100% (873/873), done.
remote: Total 1754 (delta 905), reused 1663 (delta 814), pack-reused 0
Receiving objects: 100% (1754/1754), 6.93 MiB | 99.00 KiB/s, done.
Resolving deltas: 100% (905/905), completed with 64 local objects.

これで問題なくcloneに成功した。

depthオプションについて

git clone で --depth オプションを使うと、
指定したコミット数で刈り取ることができる。

Git のドキュメントを読むと、
depthオプションを使ったcloneのことを
「シャロークローン (shallow clone)」と呼ぶらしい。

git fetch unshallowについて

git fetch unshallowとは、
そのリポジトリにフェッチされていない全ての履歴をフェッチすることができる。
つまり、shallow cloneしたリポジトリであっても、
git fetch --unshallowを実行することで過去の履歴も追うことが可能。

なんでearlyという名前?

これは自分がちょっと疑問に思ったので軽めに調査。
どうやらHTTPレスポンスに「425エラー(Too Early Experimental)」があり、
この意味とマッチしてそう(語源はしっかりと調べられておらず…)

引用元:425エラーとは

425エラー(Too Early Experimental)とは、HTTPステータスコードの一種で、通常はウェブブラウザからウェブサーバーへのリクエスト時に発生します。一般的に、ウェブブラウザがウェブサーバーに対して情報を要求した際、そのリクエストが早すぎると判断された場合にこのエラーが表示されます。

補足

結構Gitでcloneする際には、shallow cloneは使われているみたいです。
歴史が深い現場だと活躍するようですね。
私はまだ小規模で歴史が浅い開発経験しかないので、
いつかはレガシーな現場の大リフォームも行ってみたいものです。

参考

2
3
2

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