.gitignore
文件是Git版本控制系统中一种非常有用的文件。它用于指定哪些文件或文件夹不应该被Git跟踪和提交到代码仓库中。
具体作用如下:
-
忽略不需要跟踪的文件: 通常在项目中会产生一些临时文件、编译生成的文件等,这些文件不需要被版本控制,把它们添加到
.gitignore
文件可以避免误提交。 -
提高提交效率: 不跟踪无关文件可以减少仓库的体积,加快提交和克隆的速度。
-
保护敏感信息: 有时项目中会包含一些敏感信息,如密码、API密钥等,把这些添加到
.gitignore
可以避免无意中将它们提交到公共仓库。 -
统一团队开发环境: 团队开发时,每个人的开发环境可能略有不同,通过在
.gitignore
中忽略这些差异,可以确保团队成员使用同样的文件。
通常情况下,可以在项目根目录创建一个.gitignore
文件,并添加需要忽略的文件或文件夹的模式。Git提供了一些常见的.gitignore
模板,开发者也可以根据实际需求自行编写。
总之,.gitignore
文件是Git工作流中非常重要的一部分,合理使用它可以大大提高代码管理的效率和质量。
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
**/*.pyc
# 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/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
# 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/
env.bak/
venv.bak/
# mkdocs documentation
/site
# mypy
.mypy_cache/
# custom
/data
.vscode
.idea
*.pkl
*.pkl.json
*.log.json
benchlist.txt
work_dirs/
.cache/
# Profile
*.prof
# lmdb
*.mdb
# avoid soft links created by MIM
pyskl/configs/*
pyskl/tools/*
# unignore ipython notebook files in demo
!demo/*.ipynb
pyskl/.mim
.VScodeCounter
tmp/*
examples/extract_diving48_skeleton/*json
examples/extract_diving48_skeleton/*list
examples/extract_diving48_skeleton/*pkl
configs/gen_config.ipynb
dev.ipynb
test.ipynb
这是一个非常详细的 .gitignore
文件示例,主要包括以下几个部分:
-
Python 相关: 忽略 Python 编译生成的字节码文件(
*.py[cod]
)、__pycache__/
目录等。 -
打包和分发: 忽略 Python 打包和发布时生成的文件,如
build/
、dist/
、*.egg
等。 -
测试和覆盖报告: 忽略单元测试和覆盖率报告文件,如
htmlcov/
、.coverage
等。 -
临时文件和日志: 忽略编辑器、IDE 生成的临时文件,如
.ipynb_checkpoints/
、.vscode/
等。同时也忽略日志文件。 -
环境配置: 忽略虚拟环境文件夹,如
env/
、venv/
等。 -
项目相关: 忽略一些项目特定的文件和文件夹,如
data/
、work_dirs/
、*.pkl
等。
总的来说,这个 .gitignore
文件涵盖了 Python 项目中常见的各种可忽略文件,可以作为一个很好的参考模板。开发者可以根据实际项目需求对其进行适当的调整和补充。合理使用 .gitignore
文件可以帮助我们更好地管理代码仓库,提高工作效率。