Documents

GitのLarge files detectedの解消方法


大きいファイルはコミットまではできるけど、pushができなくなります。当たり前だけど制限かけているんですね。

$ git push origin main
Enumerating objects: 9471, done.
Counting objects: 100% (9471/9471), done.
Delta compression using up to 8 threads
Compressing objects: 100% (8585/8585), done.
Writing objects: 100% (9444/9444), 1.80 GiB | 3.27 MiB/s, done.
Total 9444 (delta 878), reused 9388 (delta 836), pack-reused 0
remote: Resolving deltas: 100% (878/878), completed with 20 local objects.
remote: warning: File document/foobar.js is 82.06 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
To https://github.com/example/foobar.git
 ! [remote rejected]   main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://github.com/example/foobar.git'

今回はdocument/foobar.jsが82.06 MBで上限が50.00 MBだからダメだと言われています。このような場合は、

$ git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch document/foobar.js'

を実行してください。これで push できるようになります。
しかし同様にfatal: Out of memory? mmap failed: xxxxxxxxxxxxxxというエラーも出てきたりするので、これも処理してやらないといけないです。

fatal: Out of memory? mmap failed: ???????????
fatal: index-pack failed

自前のサーバーやPCでは割り当てるメモリの容量をふやせばたいてい問題ないですがレンタルサーバーなどの場合は問い合わせないとダメな場合があるかもです。.git/configに以下を追記します。

[core]
packedGitLimit = 128m
packedGitWindowSize = 128m

[pack]
deltaCacheSize = 128m
packSizeLimit = 128m
windowMemory = 128m

これでだいたい解決します。メモリの量は便宜調整してみてください。
これでダメだったら最初からリポジトリ作り直すっていうのがいちばん早いです。



2022.04.13