Python gitignore 中应该包含什么,如何将 env 文件夹放入 gitignore 中,我的文件夹结构是否正确?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36033572/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 17:19:23  来源:igfitidea点击:

what should be in gitignore, and how do I put env folder to gitignore and is my folder structure correct?

pythondjango

提问by em four

I'm about to deploy my project. and I see I did't create gitignore before I uploaded to bitbucket. Now I created gitignore, and wasn't sure what to add so I googled and found Recommended .gitignore file for Python projects?according to this, this is the best one

我即将部署我的项目。我发现在上传到 bitbucket 之前我没有创建 gitignore。现在我创建了 gitignore,但不确定要添加什么,所以我用谷歌搜索并找到了 Python 项目的推荐 .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/ 

but I don't even know I have those things in my project. Also I saw I'm suppose to ignore virtualenv folder too. I have

但我什至不知道我的项目中有这些东西。我也看到我也想忽略 virtualenv 文件夹。我有

project
----project(inside here my files exist)
----env
----static
----.gitignore
----Read_Me.txt
----requirements.txt

回答by Mathieu Dfr

Your env folder should be in the gitignore yeah, but it doesn't have to be in your project folder. You can put everything you want in your gitignore, mine looks like (for a really big project) for example :

您的 env 文件夹应该在 gitignore 中,是的,但它不必在您的项目文件夹中。你可以把你想要的一切放在你的 gitignore 中,我的看起来像(对于一个非常大的项目)例如:

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
db.sqlite3
migrations/
media/
settings.py
# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib64/
parts/
sdist/
var/
*.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 logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

Your folder structure seems good, i would add some dirs to it, to optimize your code and directory architecture, mine looks like that, and that's pretty awesome, but you can do what you want for all your project :

您的文件夹结构看起来不错,我会向其中添加一些目录,以优化您的代码和目录架构,我的看起来像这样,这非常棒,但是您可以为所有项目做您想做的事情:

project/
---project/
---app1/
---app2/
------migrations/
------url/
---------__init__.py
---------url1.py
---------url2.py
------views/
---------__init__.py
---------view1.py
---------view2.py
------forms/
---------__init__.py
---------form1.py
------models/
---------__init__.py
---------model1.py
---------model2.py
---app3/
---static/
---templates/
------app1/
------app2/
---------view1/
-------------home.html
---------layout.html
------app3/
---templatetags/
---manage.py

This project structure allow you to separate the differents templates of all your app, better to modify them quickly and easily. It allow you to have a refactored code inside each app, it permits to prevent futurs code error (4000 codes lines in files comes really quickly so be carefull !).

这种项目结构允许您分离所有应用程序的不同模板,更好地快速轻松地修改它们。它允许您在每个应用程序中拥有重构的代码,它可以防止未来的代码错误(文件中的 4000 行代码非常快,所以要小心!)。

There is too separate folder for all your statics and templatetags, so you can use it everywhere in your templates, pretty awesome !

您所有的静态和模板标签都有一个单独的文件夹,因此您可以在模板中的任何地方使用它,非常棒!

Remember, you can do everything you want with your folder structure, the best you can do is the best that fits you :)

请记住,您可以使用文件夹结构做任何您想做的事情,您能做的最好的是最适合您的 :)

Hope it helps !

希望能帮助到你 !

回答by loutre

Your virtualenv folder can be completely outside your tracked folder. Just add requirements.txt in it.

您的 virtualenv 文件夹可以完全在您跟踪的文件夹之外。只需在其中添加 requirements.txt 即可。