__pycache__ 是 Python 的编译缓存(.pyc 那些),没必要进 Git
先 ignore 掉,.gitignore 加一行:
**/__pycache__/
已经提交过的,从索引里删掉(本地文件留着):
git rm -r --cached __pycache__
git commit -m "Remove __pycache__ from version control"
git push
这样之后就干净了。但如果它早混进历史,上面这招只是不再跟踪,历史里的文件还在。想彻底抹掉得重写历史,用 BFG Repo-Cleaner(Arch 上 yay -S bfg-repo-cleaner,其它平台去 release 页 下 jar):
bfg --delete-folders '__pycache__' --no-blob-protection
git reflog expire --expire=now --all
git gc --prune=now --aggressive
git push --force
--force 会改写远程历史,多人协作的仓库先跟队友打招呼,别把别人的分支冲了