【Git】从Git远程存储库中删除所有.pyc编译文件;附常用gitignore配置

问题

提交的时候使用git add --all,然后把所有文件都推送到了远程仓库中。

现在我想在远程仓库中删除它们,例如*.pyc文件。

解决方式

git rm *.pyc --cached

删除的时候,如果遇到报错fatal: pathspec 'xxx.pyc' did not match any files的情况,可能是因为没提交…我解决方式是commit一下,然后push上去,就好了,不知道为啥。有可能是因为.gitignore没有提交,占用了某些文件吧。
在这里插入图片描述

附:常用的.gitignore配置

# Created by .ignore support plugin (hsz.mobi)
### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
*.pyc

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.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 log
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:

local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

.idea
.update
migrations
发布了610 篇原创文章 · 获赞 232 · 访问量 23万+

猜你喜欢

转载自blog.csdn.net/sinat_42483341/article/details/104161380