LoginSignup
65
44

More than 5 years have passed since last update.

GitHubで100 MB以上のファイルをpushしようとしてエラーになった後の解決方法

Last updated at Posted at 2019-03-26

これ何?

  • GitHubで100 MB以上のファイルをpushしようとしてエラーになった時の解決方法です!
  • ネットで調べたのですが、色々な情報があって解決に時間がかかったので共有します

症状

1. Githubの100MB制限に引っかかって、pushを拒否される

RubyMine-2018.3.5.dmgという288.73 MBのファイルをGitHubにあげようとします。

$ git add RubyMine-2018.3.5.dmg
$ git commit -m '100MB以上のpushテスト'
$ git push origin master
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 287.74 MiB | 3.82 MiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: 15e3dbc55f1a83b933fa4fd59e80c81e
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File RubyMine-2018.3.5.dmg is 288.73 MB; this exceeds GitHub's file size limit of 100.00 MB
To github.com:***.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@github.com:***.git'

2. おっと間違ったってことで、大きなコミットを無かったことにする

 $ git reset --hard HEAD

3. 新しくファイルを追加するがpushを拒否される(困った!!)

$ touch test.txt
$ git add test.txt 
$ git commit -m 'test'
$ git push origin master
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 287.74 MiB | 3.82 MiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: 15e3dbc55f1a83b933fa4fd59e80c81e
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File RubyMine-2018.3.5.dmg is 288.73 MB; this exceeds GitHub's file size limit of 100.00 MB
To github.com:***.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@github.com:***.git'

4. GitHubの公式ヘルプを読んでみよう(でもダメじゃん(泣))

以下、参照した公式ヘルプです。
https://help.github.com/en/articles/removing-files-from-a-repositorys-history

$ git rm --cached RubyMine-2018.3.5.dmg
$ git commit --amend -CHEAD
$ git push
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 287.74 MiB | 3.82 MiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: 15e3dbc55f1a83b933fa4fd59e80c81e
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File RubyMine-2018.3.5.dmg is 288.73 MB; this exceeds GitHub's file size limit of 100.00 MB
To github.com:***.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@github.com:***.git'

うーむやっぱりダメです。
悲しいです。

解決方法

色々と検証してみた結果、解決できました!

1. 巨大ファイルのコミット前のリビジョンを調べる

まずは、git logで巨大ファイルのリビジョンを調べます。
下記の例だと、

  • c0ddee8321b54e0aee232ae0e8f51fa084a71f82 で巨大ファイルをコミットしている
  • 27a1789e1248b097cffe26037b3ecc23a3467333 に戻せば良い

って感じになります。

$ git log
commit a813a9568372ebab5ad8c8d98f828c22667f2ca7 (HEAD -> master)
Author: 藤澤勇樹 <yuki_fujisawa@fujisawayuukinoMacBook-Pro.local>
Date:   Tue Mar 26 11:42:49 2019 +0900

    Revert "Revert コメント"

    This reverts commit 27a1789e1248b097cffe26037b3ecc23a3467333.

commit 3bc118af7a742fa714027ab220fdce42cd7edaad
Author: YukiFujisawa <g031y148yuki@gmail.com>
Date:   Sat Feb 16 17:59:18 2019 +0900

    Revert コメント

commit c0ddee8321b54e0aee232ae0e8f51fa084a71f82
Author: 藤澤勇樹 <yuki_fujisawa@fujisawayuukinoMacBook-Pro.local>
Date:   Tue Mar 26 11:20:42 2019 +0900

    RubyMine

commit 27a1789e1248b097cffe26037b3ecc23a3467333 (origin/master, origin/HEAD)
Author: YukiFujisawa <g031y148yuki@gmail.com>

2. 巨大ファイルのコミット前のリビジョンにresetする

27a1789e1248b097cffe26037b3ecc23a3467333 に戻します。

$ git reset --soft 27a1789e1248b097cffe26037b3ecc23a3467333

3. pushできるようになったことを確認する

$ git add test.txt
$ git commit -m 'テスト'
$ git push origin master
Counting objects: 4, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 894 bytes | 894.00 KiB/s, done.
Total 4 (delta 2), reused 1 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:***.git
   27a1789..6e6cc27  master -> master

無事にpushできるようになりました!

まとめ

  1. 巨大ファイルのコミットのリビジョンを調べる
  2. 巨大ファイルのコミット前のリビジョンにresetする

以上で解決できます。

65
44
4

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
65
44