跳至内容
Xeron
Go back

清理 Git 中的 __pycache__

发布于:
建议修改

__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 会改写远程历史,多人协作的仓库先跟队友打招呼,别把别人的分支冲了


建议修改
在以下平台分享此文章:

上一篇
解决 Web3 交易 Underpriced 错误
下一篇
加密货币交易思考