为什么Git ignore对__pycache__文件夹不起作用?[duplicate]

mnemlml8  于 2022-12-25  发布在  Git
关注(0)|答案(1)|浏览(278)
    • 此问题在此处已有答案**:

How do I make Git forget about a file that was tracked, but is now in .gitignore?(34个答案)
去年关闭了。
我有3个路径,我试图忽略在我的.gitignore文件:

aws_scripts/python/aws_tools/__pycache__/
.vscode/
aws_scripts/output_files/
aws_scripts/source_files/

aws_scripts/python/aws_tools/__pycache__/外,所有内容都将被忽略

git status
On branch develop
Your branch is up to date with 'origin/develop'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   aws_scripts/python/aws_tools/__pycache__/ec2_mongo.cpython-39.pyc

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .gitignore

no changes added to commit (use "git add" and/or "git commit -a")

如果我注解掉.gitignore中的行,那么这些目录在git status中会再次出现,其中的行被注解掉了:

#aws_scripts/python/aws_tools/__pycache__/
#.vscode/
#aws_scripts/output_files/
#aws_scripts/source_files/

git status中的结果:

git status
On branch develop
Your branch is up to date with 'origin/develop'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   aws_scripts/python/aws_tools/__pycache__/ec2_mongo.cpython-39.pyc

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .gitignore
        .vscode/
        aws_scripts/output_files/
        aws_scripts/source_files/

为什么只有__pycache__目录不能与.gitignore一起使用?

to94eoyn

to94eoyn1#

注意git status输出中的modified,这意味着您已经添加并提交了__pycache__
git rm -rf <PATH> it,提交,它应该开始被正确地忽略。
从一开始就使用官方的.gitignore并扩展它们不是一个坏主意:https://github.com/github/gitignore

相关问题