Using the Git version control to manage your project

Ready to work

After the project is created, the project version control up future iterations of each version will be very clear, but also help develop collaborative projects.

There is also a very important question is: on-line project, carried out in line with the configuration program running line test configuration file is not the same (for example configuration database, DEBUE mode, ALLOWED_HOSTS etc.), so we here need to create a separate file local_settings.py test line test environment,

Local_settings.py file contents are as follows:

Copy the code
# -*- coding:utf-8 -*-
# 本地的settings 不用版本控制
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'local_db.sqlite3'),
    }
}

DEBUG = True

ALLOWED_HOSTS = []
Copy the code

Note that this document is not required local_settings.py Git version control! Specific configuration will be described later.

After creating the configuration file and configuration data for local testing needed to be written, we need to let it take effect when local testing.

A better approach is implemented as follows: Finally import this file in settings.py file local_settings.py project, according to the Python file execution and the import module import mechanism, we can make a local test data used to cover the front line on the configuration, but it needs to capture abnormal, because we have no control over the local version of the test file!

settings.py file and finally adding the following code:

Then at # line can be directly used 
for online # ~ version control do not local_settings exception handling 
the try: 
    from .local_settings * Import 
the except ImportError: 
    Pass 

The process of local projects and Git remote repository connection

Local Basic Operation

First found in the local storage directory project

Right-click in the project directory - "GIt Bash Here"

Enter the command interface opens git git init

The local configuration file and the local_settings.py generated database files, etc. other unnecessary files ignored

Use gitignore: gitignore Download

(1) After entering the above Download gitignore to find Python.gitignore, copy the code inside it, or directly by my side will do well to copy:

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

# 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

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
#   According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
#   However, in case of collaboration, if having platform-specific dependencies or dependencies
#   having no cross-platform support, pipenv may install dependencies that don't work, or not
#   install all needed dependencies.
#Pipfile.lock

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

# Pyre type checker
.pyre/
Python.ignore

(2)然后,在自己项目的“根目录”下新建一个名为“.gitignore”的文件,先把上面的代码复制进去。

(3)通过仔细看里面的代码我们可以发现:忽略文件的名单中已经有了我们之前创建好的“local_settings.py”文件了——看来这已经是一个不成文的规定了~~如果你非要把本地测试的配置文件改成其他的名字,那么一定要记得把你自己的这个本地的测试文件的名字写在.gitignore文件中去!

(4) Configuration on sqllit database: .gitignore file in addition to the written local_settings.py, in fact, there are "db.sqlite3", is generated by default sqllit database file. But let's look at the above local_settings.py own configuration file, I put locally generated database name changed local_db.sqlite3. So we have to put this local_db.sqlite3 .gitignore file written to go!

(5) PyCharm will be automatically generated when you create a project in the root directory of the project in a directory named .idea, we should put this directory is also added to the list - Note added that the format of the catalog: .idea /

(6) Last remind you that: .gitignore document should filter out the virtual environment, there is a default filter to a virtual environment, but need to pay attention to the corresponding directory name!

Execute git status View

Execute git git status command to view the files and directories under version control:

Execute git add. Save the file to cache

 

git add .

 

Performing git commit -m 'initialization' added description file

git commit -m 'initialization'

The distal end of the operation

The project is the use of cloud code version control.

Create a private warehouse in the cloud code

After creating a private warehouse, this page will appear the following:

Connect the local and remote repository

According to the above tips, in the local and remote repository connection configurations:

We're done!

In this case you also have a line of code!

In the future you will be able to develop a project using the version control - their own development and collaborative development easy.

Guess you like

Origin www.cnblogs.com/ryxiong-blog/p/11611527.html