我试图收集一些默认设置,我意识到我没有标准的一件事是.gitignore文件。有一个很棒的帖子为Visual Studio项目展示了一个很好的.gitignore,但我没有看到很多关于Python和相关工具(PyGTK, Django)的建议。

到目前为止,我已经……

*.pyc
*.pyo

...对于编译的对象和…

build/
dist/

...对于setuptools输出。

是否有.gitignore文件的最佳实践,我可以从哪里获得更多关于这些最佳实践的信息?


当前回答

Github有一个很棒的样板文件。gitignore

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

# C extensions
*.so

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

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

# Unit test / coverage reports
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# Rope
.ropeproject

# Django stuff:
*.log
*.pot

# Sphinx documentation
docs/_build/

其他回答

当使用构建时,我在.gitignore(连同*。Pyo和*.pyc):

.installed.cfg
bin
develop-eggs
dist
downloads
eggs
parts
src/*.egg-info
lib
lib64

感谢雅各布·卡普兰-莫斯

另外,我倾向于把.svn放在里面,因为我们在我工作的地方使用了几个scm。

以下是其他一些可能被setuptools遗留的文件:

MANIFEST
*.egg-info

Local_settings.py,用于django项目。

*~为所有项目。

涵盖了大多数一般的东西

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

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

参考:python .gitignore

一个问题是,如果你也想使用git来完成你的项目。如果是这样的话,你可能想要从存储库中排除本地sqlite文件,同样的情况可能也适用于文件上传(主要是在你的媒体文件夹中)。(我现在说的是django,因为你的问题也带有django的标签)