LoginSignup
12
8

More than 5 years have passed since last update.

Git push がやたら落ちていると思ったら、ファイルサイズ・数がやたら多かった場合

Last updated at Posted at 2015-04-02

Railsでプロジェクトを作って外部リポジトリにpushしようとしたときのこと。

プロジェクトを始めたばかりなのに、サイズやファイル数がとんでもないことになっていました。

$ git push origin master
Counting objects: 26593, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (24906/24906), done.
Writing objects: 100% (26593/26593), 157.41 MiB | 160.00 KiB/s, done.
Total 26593 (delta 4255), reused 0 (delta 0)
remote: error: GH001: Large files detected.
remote: error: Trace: 
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File vendor/bundle/ruby/2.2.0/gems/libv8-3.16.14.7-x86_64-darwin-14/vendor/v8/out/x64.release/libv8_base.a is 150.14 MB; this exceeds GitHub's file size limit of 100 MB
To git@github.com:hoge/hgoe.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@github.com:hoge/hoge.git'

対応

.gitを消してgit initからやり直す

.git/objects/以下に大量のファイルが出来てしまっています。おそらくこの辺に問題がありそうなのですが、急ぎの対応をしたかったので、一旦スルー。。。

git init からやり直すとすんなりいきました。

$ rm -rf .git && git init
$ git add .
$ git commit -am "retry"

結果

$ git push bb master
Counting objects: 135, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (118/118), done.
Writing objects: 100% (135/135), 162.30 KiB | 0 bytes/s, done.
Total 135 (delta 10), reused 0 (delta 0)
To 
 * [new branch]      master -> master

このオブジェクト数の差...

# before
26593, 157.41 MiB

# after
135, 162.30 KiB

原因

gemファイルをリポジトリに含めて一度commitしてしまった

gemファイルが多ければ多いほどファイルサイズが大きくなってしまいます。
今回は $ bundle install --path vendor/bundleとしてgemの中身をvendor/bundleに入れていま。
基本的に.gitignoreでvendor/bundleをgitから省いていましたが、cacheの都合で、.gitignoreの更新が反映されておらず、vendor/bundleをcommitしてました。

cacheを削除するのは以下の様にすればできます。

$ git rm -r --cached .
12
8
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
12
8