🍱

remote: error: GH001: Large files detected.の対処法

2025/01/26に公開

背景

remote: error: File XXX.asset is 131.05 MB; this exceeds GitHub's file size limit of 100.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/t-esserac-t/CharmingAbyss.git
 ! [remote rejected] dialog -> dialog (pre-receive hook declined)
error: failed to push some refs to 'https://github.com/sample.git'

必要な編集をした後git pushしたら上記のようなエラーが出て、pushに失敗した。
ここで初めてGit LFSというものの存在を知ったので、セットアップ方法と詰まった点をまとめておきます。

デバイスの仕様

プロセッサ Intel(R) Core(TM) i7-14700KF 3.40 GHz
実装 RAM 64.0 GB (63.8 GB 使用可能)
システムの種類 64 ビット オペレーティング システム、x64 ベース プロセッサ

Windowsの仕様

エディション Windows 11 Home
バージョン 23H2
インストール日 ‎2024/‎10/‎23
OS ビルド 22631.4317

Git LFSとは

https://git-lfs.com/
音声・映像ファイルなど、大きなサイズのファイルをテキストポインタに置き換え、ファイルそのものはリモートサーバに保存しておくGit拡張機能のこと。
(メールにファイルを添付せず、ストレージサービスで発行したURLを記載するようなイメージ)

Git LFSのインストール

Git LFSがインストールされていない場合、以下のコマンドでインストール。

git lfs install

無事インストールされたかは以下のコマンドで確認できる。

git lfs version
git-lfs/3.5.1 (GitHub; windows amd64; go 1.21.7; git e237bb3a)

LFSトラッキングの設定ファイルを作成する

トラッキングの設定を入れたいフォルダまで移動し、以下のようなコマンドを実行する。

git lfs track "foo/bar/test.asset"
git lfs track "*.wav"

トラッキング設定の確認

設定は .gitattributes に保存される。
上述のような設定が正しく反映された場合は、.gitattributesの中身は以下のようになる。

foo/bar/test.asset filter=lfs diff=lfs merge=lfs -text
*.wav filter=lfs diff=lfs merge=lfs -text

LFS設定をcommitする

作成した.gitattributesファイルをcommitする。

git add .gitattributes
git commit -m "LFS設定を反映"

その後、必要な変更点をcommitし、必要であればリモートへもpushする。

過去の履歴に大きなファイルがある場合

Git LFSを設定する前に、通常のGitで大きなファイルを含んだcommitが正常に終了した場合は、そのファイルが履歴に残っている(らしい)。
この場合は前述のようにLFSの設定を行ってpushするだけでは同様のエラーが返ってくるため、git-filter-repoのようなツールを用いて履歴をクリーンアップ -> LFSで管理するよう設定する必要がある。

https://qiita.com/propella/items/7b149c8e979b0d9fe416
https://github.com/newren/git-filter-repo/
https://htmlpreview.github.io/?https://github.com/newren/git-filter-repo/blob/docs/html/git-filter-repo.html

参考

https://qiita.com/ikmski/items/0faf9eae808ff29f6358
https://qiita.com/kanaya/items/ad52f25da32cb5aa19e6
https://docs.github.com/ja/repositories/working-with-files/managing-large-files/configuring-git-large-file-storage

Discussion