- 此问题在此处已有答案**:
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
一起使用?
1条答案
按热度按时间to94eoyn1#
注意
git status
输出中的modified
,这意味着您已经添加并提交了__pycache__
。git rm -rf <PATH>
it,提交,它应该开始被正确地忽略。从一开始就使用官方的
.gitignore
并扩展它们不是一个坏主意:https://github.com/github/gitignore