英文:
Remove all __pycache__/ folders from git history
问题
__pycache__/
未添加到.gitignore
,导致__pycache__/
文件夹在整个git历史中被跟踪和提交。
我尝试了以下命令来从整个git历史中删除它:
git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch __pycache/" HEAD
这似乎对顶层根目录中的__pycache__/
有效,但子文件夹仍然有它们自己的__pycache__/
文件夹,尽管使用了-r
递归标志。
如何从git历史中删除所有文件夹中的所有__pycache__/
实例?
英文:
__pycache__/
was not added to the .gitignore
, resulting in __pycache__/
folders being tracked and committed throughout the git history.
I've attempted this command to remove it from the entire git history
git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch __pycache__/" HEAD
Which seems to have worked for the __pycache__/
in the top-level root directory, but subfolders still have their own __pycache__/
folders, despite the -r
recursive flag used.
How can I remove all instances of __pycache__/
throughout all folders from a git history?
答案1
得分: 2
递归标志 -r
不表示“在整个树中查找模式”,而表示“查找顶层目录(们),然后删除这些目录下的所有内容”。要在整个树中删除模式,还需要使用递归模式:
git filter-branch -f --index-filter "git rm --cached --ignore-unmatch */__pycache__/*" HEAD
更新. 使用 [tag:git-filter-repo]:
git filter-repo --force --path-glob '*/__pycache/' --invert-paths
英文:
Recursive flag -r
doesn't mean "find the pattern all over the tree", it means "find top-level directory(ies) that match the pattern and remove everything below these directories recursively". To remove a pattern all over the tree you also need to use recursive pattern:
git filter-branch -f --index-filter "git rm --cached --ignore-unmatch */__pycache__/*" HEAD
Upd. Using [tag:git-filter-repo]:
git filter-repo --force --path-glob '*/__pycache__/' --invert-paths
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论