我不能忽略 Django 上的 pycache 和 db.sqlite,即使它在 .gitignore 中引用它们

I cannot ignore pycache and db.sqlite on Django even though it refers them at .gitignore

我想忽略pycache的变化和Django项目的db.sqlite。我在 .gitignore 引用它们,但是 git 捕捉到它们的变化。如果你知道,你能告诉我什么是问题吗? 我在句末附上了我的 .gitignore。

.git忽略

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
media/
settings.py

.idea/

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
#  Usually these files are written by a python script from a template
#  before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# IPython Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# dotenv
.env

# virtualenv
.venv/
venv/
ENV/

# Spyder project settings
.spyderproject

# Rope project settings
.ropeproject

# Database stuff
*.sqlite3
migrations/
db.sqlite3

# Atom config file
.editorconfig

# Other unwanted stuff
.idea
.DS_Store
.DS_STORE

如下,我已经解决了

git rm -r --cached .   # will delete whole git history, use with caution
git add .
git commit -m
git push ~

作为@lalala 回答中 git rm -r --cached . 的替代方法,您可以使用 git rm --cached <filename> 定位您实际想要从缓存中删除的文件。 这通常更可取,因为它不会影响其他文件。您可以使用 *.sqlite 等元字符代替 <filename> 来定位更多文件。