django - 在 Django 中迁移时出现 Git 文件问题
问题描述
我的 Django 项目中有以下结构
gitignore 是https://www.toptal.com/developers/gitignore/api/django建议的
初始化 GIT 的步骤是:使用 apps/A 和 apps/B 创建项目,创建 .gitignore 文件并运行git init
.
然后我跑makemigrations
了migrate
当从 master 开始,使用 apps/ZApp 创建一个名为 Z 的新分支时,就会出现问题,创建一个新模型并makemigrations
从migrate
该分支执行。因此:
$ git checkout -b Z
$ cd apps
$ django-admin startapp Z
$ cd ..
然后我申请makemigrations
并migrate
返回到主人......当我在主人时,我看到那些应该被忽略的文件,我找不到原因......他们不应该在那里......所有文件应该在各自的分支
没看懂。。。有人帮帮我
更新:我的 gitignore
### Personal ###
secret.json
### Django ###
*.log
*.pot
*.pyc
__pycache__/
local_settings.py
db.sqlite3
db.sqlite3-journal
media
# 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
# 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
# poetry
#poetry.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
.env/
.venv/
env/
venv/
ENV/
env.bak/
venv.bak/
pythonenv*
# 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/
# operating system-related files
# file properties cache/storage on macOS
*.DS_Store
# thumbnail cache on Windows
Thumbs.db
# profiling data
.prof
解决方案
这是预期的行为。Git 根本没有对它忽略的文件做任何事情。这意味着如果在您打开一个分支时创建 .pyc 文件,然后切换到另一个分支,则 .pyc 文件不会发生任何事情,因为您所做的只是切换 git 分支,而这些文件会被 git 忽略。
如果你喜欢,你可以添加一个 post-checkout钩子,每次你签出一个分支时删除所有pycache目录和 .pyc 文件。
推荐阅读
- c# - 带有复选框的列表框 - 查看每个项目的代码 IsChecked = true
- python - 等效于 Python 3 中的 thread.interrupt_main()
- python - 使用 if-elif-else 在 Python 中读取不同的 Excel 工作表
- php - 从 WooCommerce 中的 WP 管理员将产品添加到客户的购物车
- javascript - Moment js没有将日期转换为所需的格式
- winforms - 如何从 csv 文件列中获取不同的值到组合框中?
- node.js - ETXTBSY:运行 npm install 时文本文件很忙(通过带有 Unix 的 Vagrant - 桌面操作系统是 Windows)
- angular - 如何在组件之间使用 Angular 7 cdkDropList?
- jquery - 如何使用 jQuery 获取 td 标签中输入标签的值
- php - 如何在 plesk centos7 上安装 ffmpeg php 扩展