でかいzipとか秘匿ファイルとかpushしちゃった時の完全削除コマンド

1
2
3
4
5
6
7
8
9
10
11
12
13
$ git filter-branch --tree-filter "rm -f [対象ファイル]" HEAD
Rewrite 75c38177c79f8b49901fae60d111cc06d26ead1e (399/441) (9 seconds passed, remaining 0 predicted)
Ref 'refs/heads/master' was rewritten

$ git gc --aggressive --prune=now
Enumerating objects: 3061, done.
Counting objects: 100% (3061/3061), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2827/2827), done.
Writing objects: 100% (3061/3061), done.
Total 3061 (delta 1895), reused 222 (delta 0)

$ git push -f

ディレクトリの場合の filter-branchは以下

1
$ git filter-branch --tree-filter "rm -f -r [対象ディレクトリ]" HEAD