Python项目中的.gitignore配置

在Git项目中,.gitignore 文件用于指定哪些文件和目录应该被Git忽略,不纳入版本控制。对于Python项目,通常需要忽略一些特定的文件和目录,如编译生成的文件、虚拟环境、日志文件等。以下是一个常见的Python项目 .gitignore 配置示例:

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

# C extensions
*.so

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

# 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/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/
docs/_build/doctrees
docs/_build/html
docs/_build/latex
docs/_build/man
docs/_build/texinfo
docs/_build/text
docs/_build/epub

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints
*.ipynb

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

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

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# VS Code
.vscode/

# macOS
.DS_Store

# Windows
Thumbs.db
ehthumbs.db
Desktop.ini
$RECYCLE.BIN/
*.cab
*.msi
*.msm
*.msp

说明

  • 编译生成的文件__pycache__/*.py[cod] 是Python生成的缓存文件,应该忽略。
  • 包管理:例如 build/, dist/, *.egg-info/ 等目录和文件是生成的安装包和分发文件,也应该忽略。
  • 测试和覆盖率报告:例如 .tox/, .coverage, coverage.xml 等文件是测试工具生成的报告文件,应该忽略。
  • 虚拟环境:例如 .env, venv/ 等目录是虚拟环境,通常不需要纳入版本控制。
  • 日志文件:例如 *.log 是日志文件,不需要纳入版本控制。
  • 编辑器和IDE设置:例如 .vscode/ 是VS Code的设置目录,应该忽略。

可以根据自己的项目需求,进一步调整和扩展 .gitignore 文件的内容。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

uncle_ll

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值