gitにて大容量のファイルを探して履歴から消す

git

githubの個人アカウントにてprivate repositoryが作り放題になったので個人で開発しているソースコードを載せようとしたら、100MB以上のファイルが存在して移行できなかったのでやり方をメモ。

以下のやり方は、バックアップのことは考えずにやってしまっているのでちゃんとやる場合は、こちらの記事を参考にやったほうが良いです。

% wget https://raw.githubusercontent.com/RazorFlow/framework/master/git_find_big.sh
% chmod git_find_big.sh
% ./git_find_big.sh
All sizes are in kB's. The pack column is the size of the object, compressed, inside the pack file.
size    pack    SHA                                       location
118513  117754  0f44a922dad3f8c8978314f5b931ca855d2dbd05  public/dist/app/macos/郵便番号検索_v1.0.0.zip
50401   50248   43d6d994ec9a7c9369678426bcafbbbf1fea3ba3  public/dist/app/windows/郵便番号検索_v1.0.0.zip
17743   2551    b6cf8085e511bd229d401a46f98140f7efcfc4d7  test/fixtures/KEN_ALL.CSV
5096    1160    75fdc7ed4609fdd02c619685294e4e3d4d27bf68  test/fixtures/concat.csv
4370    837     083ad57d48ab1a08fec1e5e611493d6eee7871eb  test/fixtures/JIGYOSYO.CSV
1298    694     ce74201c4d695087dd2d732f15e311588481aa9b  test/fixtures/KEN_ALL.CSV
1164    333     5d571ecc63e17d18a4e95299b31598c5b3034437  test/fixtures/kyk3.csv
1112    321     d1e6c407c12cf00db2260204f08c12178afed63f  test/fixtures/kyk1.csv
1047    291     a5863b0a1e3e30c5180261c0406b141e65d84135  test/fixtures/kyk4.csv

あとは、ファイルごとに以下の繰り返し。以下の4コマンドを1ファイルに対して1セットで実行する必要がある。

% git filter-branch --index-filter 'git rm --cached --ignore-unmatch test/fixtures/kyk4.csv' HEAD
% git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
% git reflog expire --expire=now --all
% git gc --prune=now

コメント