Remover arquivo muito grande que foi no commit

Recentemente passei por este problema, estava trabalhando em um projeto de IA onde muitos arquivos excedem os 100 Mb do Github, assim como em outros reposítorios.

O problema que fiz o git add, e git commit com os arquivos superiores ao limite e depois de tentar fazer o push algumas vezes comecei a ter problema para resolver.

O erro era o seguinte:

remote: Resolving deltas: 100% (15/15), done.
remote: warning: File models/CASIA-WebFace-ResNetv1/20180408-102900.pb is 91.31 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: 93815bc0682a06d8f7104e3af2c92d71
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File models/CASIA-WebFace-ResNetv1/model-20180408-102900.ckpt-90.data-00000-of-00001 is 110.33 MB; this exceeds GitHub's file size limit of 100.00 MB

A solução foi:

git filter-branch --tree-filter 'rm -rf pasta/seuarquivo' HEAD
git push

Ou para a pasta toda e sub arquivos:

git filter-branch --tree-filter 'rm -rf pasta/subasta/' HEAD
git push

Quem sabe você tenha mais de um commit e precise forçar a limpeza, aí basta inserir o -f depois do filter-brach, desta forma:

git filter-branch -f --tree-filter 'rm -rf pasta/subasta/' HEAD

Pronto, assim foi resolvido 🙂

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *