python虚拟环境下 .gitignore 要忽略什么

在Python虚拟环境中,.gitignore 文件用于告诉 Git 哪些文件和目录是不需要添加到版本控制中的。以下是一个典型的 Python 虚拟环境中 .gitignore 文件的内容:

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

# C extensions
*.so

# Distribution / packaging
.Python
env/
venv/
ENV/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-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
.hypothesis/
.pytest_cache/
testlog/

# 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/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
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/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

这个列表不是固定的,它可能会根据你的项目和所使用的工具有所不同。例如,如果你使用的是其他数据库,你可能需要忽略其他数据库文件。如果你使用的是其他开发工具,你可能需要忽略由这些工具生成的特定文件或目录。

一般来说,你应该忽略以下内容:

  1. 虚拟环境文件夹(通常是 env/, venv/, .venv/ 等)。
  2. 编译生成的文件(如 .pyc 文件和 __pycache__ 目录)。
  3. 包分发文件夹(如 build/, dist/, *.egg-info/)。
  4. 安装器日志文件(如 pip-log.txt)。
  5. IDE 和编辑器配置文件(如 .idea/ 对于 PyCharm,.vscode/ 对于 Visual Studio Code)。
  6. 操作系统生成的文件(如 .DS_Store 对于 macOS,Thumbs.db 对于 Windows)。
  7. 测试和覆盖报告(如 .tox/, .coverage, .pytest_cache/)。
  8. 项目中特定的环境变量或配置文件(如 .env)。

创建适合你项目的 .gitignore 文件时,确保理解每个条目的目的,并根据你的项目需要进行调整。GitHub 提供了一个很好的资源库,其中包含了许多不同编程语言和框架的 .gitignore 模板,这可以作为一个很好的起点。

作者:汪汪队立大功
链接:https://juejin.cn/post/7332290436345937955

相关推荐

  1. python虚拟环境 .gitignore 忽略什么

    2024-06-14 03:06:02       10 阅读
  2. Git 忽略提交 .gitignore

    2024-06-14 03:06:02       40 阅读
  3. windows安装python virtualenv 虚拟环境

    2024-06-14 03:06:02       19 阅读
  4. ubuntu使用python3的venv虚拟环境

    2024-06-14 03:06:02       38 阅读
  5. git .gitignore忽略非必要文件提交

    2024-06-14 03:06:02       11 阅读
  6. git忽略文件.gitignore如何使用?

    2024-06-14 03:06:02       13 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-14 03:06:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-14 03:06:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-14 03:06:02       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-14 03:06:02       20 阅读

热门阅读

  1. 【AI应用探讨】— GPT-4o模型应用场景

    2024-06-14 03:06:02       7 阅读
  2. Hash路由、History路由原理及优缺点

    2024-06-14 03:06:02       9 阅读
  3. mysql和postgreSQL的区别

    2024-06-14 03:06:02       4 阅读
  4. RealAI-图像算法岗-面经

    2024-06-14 03:06:02       6 阅读
  5. 5.2 Python 名称空间与作用域

    2024-06-14 03:06:02       6 阅读
  6. Kotlin 的锁和多线程同步

    2024-06-14 03:06:02       5 阅读
  7. kotlin get() 与 set()

    2024-06-14 03:06:02       9 阅读
  8. RK3588开发笔记-100M网口自协商成1000M网口

    2024-06-14 03:06:02       9 阅读