【发布时间】:2021-04-20 15:08:44
【问题描述】:
我的 .gitignore 文件中有 3 条路径试图忽略:
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 中。
.gitignore 注释掉的行:
#aws_scripts/python/aws_tools/__pycache__/
#.vscode/
#aws_scripts/output_files/
#aws_scripts/source_files/
结果为@987654329@:
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 一起使用?
【问题讨论】:
-
您不能忽略跟踪的文件。
-
这些目录未被跟踪:
Untracked files: (use "git add <file>..." to include in what will be committed) .gitignore .vscode/ aws_scripts/output_files/ aws_scripts/source_files/但是当我将它们添加到.gitignore并且我执行 git status 时它们消失了。 -
aws_scripts/python/aws_tools/__pycache__/ec2_mongo.cpython-39.pyc是一个被跟踪的文件,否则 git 不会将它列为 modified。