Git db.sqlite 和 wsgi.py 文件在拉取时保持恢复

Git db.sqlite and wsgi.py file keep reverting on pull

我有一个使用 db.sqlite3 在本地构建的 python/django/wagtail 项目。我最初将所有内容推送到 github,然后将其拉到我的服务器。我对 wsgi 文件进行了更改,并在更新数据库的 cms 中做了一些工作。

我在本地做了一些修改。我更改了 .gitignore 以排除 db.sqlite3 和 wsgi.py。 git add .git commitgit push origin master。然后,在服务器上,sudo git pull origin master。 db.sqlite3 恢复到我进行 cms 更改之前,wsgi.py 恢复到指向我的开发设置。

我对 cms 进行了更改,但现在我需要在对 cms 进行更多更改并且不想再次覆盖数据库时进行另一次更新。 wsgi.py 是一个小修复,但仍然如此。我的 .gitignore

# Created by https://www.toptal.com/developers/gitignore/api/django
# Edit at https://www.toptal.com/developers/gitignore?templates=django

### Django ###
*.log
*.pot
*.pyc
__pycache__/
local_settings.py
db.sqlite3
db.sqlite3-journal
media
wsgi.py

# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
# in your Git repository. Update and uncomment the following line accordingly.
# <django-project-name>/staticfiles/

### Django.Python Stack ###
# Byte-compiled / optimized / DLL files
*.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
*.py,cover
.hypothesis/
.pytest_cache/
pytestdebug.log

# Translations
*.mo

# Django stuff:

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/
doc/_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

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
#.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
wow/

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

# End of https://www.toptal.com/developers/gitignore/api/django

.gitignore 添加一行不会阻止该文件被 git 跟踪 - 它只是意味着对其的更改不会显示在 git status / git diff 和类似的。要从 git 中删除它,您需要 运行 git rm name-of-file 。但是,这也会删除实际文件,因此为避免丢失数据,最好的方法是:

  • 复制 db.sqlite3
  • git rm db.sqlite3
  • 将您的文件副本移回原始文件名
  • 提交更改 git

然后,在您的实时服务器上:

  • 复制 db.sqlite3
  • git pull
  • 将您的文件副本移回原始文件名