从 git 历史记录中删除所有 __pycache__/ 文件夹

问题描述 投票:0回答:2

__pycache__/
未添加到
.gitignore
,导致
__pycache__/
文件夹在整个 git 历史记录中被跟踪和提交。

我尝试使用此命令将其从整个 git 历史记录中删除

git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch __pycache__/" HEAD

这似乎适用于顶级根目录中的

__pycache__/
,但子文件夹仍然拥有自己的
__pycache__/
文件夹,尽管使用了
-r
递归标志。

如何从 git 历史记录中删除所有文件夹中

__pycache__/
的所有实例?

git version-control
2个回答
2
投票

递归标志

-r
并不意味着“在整个树中查找模式”,它的意思是“查找与模式匹配的顶级目录并递归地删除这些目录下的所有内容”。要删除整个树上的模式,您还需要使用递归模式:

git filter-branch -f --index-filter "git rm --cached --ignore-unmatch */__pycache__/*" HEAD

更新。使用 :

git filter-repo --force --path-glob '*/__pycache__/' --invert-paths

0
投票

几乎一样:

git filter-repo --force --path __pycache__/ --invert-paths

但这对我有用。

© www.soinside.com 2019 - 2024. All rights reserved.