[英]Can I git ignore an entire branch to create a local branch that interfaces with live server, with debug set to True.?
I'm about to start deploying, and I've had some issues problems with my live server crashing, and I can't have debug set to True. 我将要开始进行部署,我的实时服务器崩溃时遇到了一些问题,并且我无法将调试设置为True。
I've got an idea of how I'd like things setup but I think I need some help. 我已经知道如何进行设置,但我认为我需要一些帮助。
I have a local branch, master
, and a local database with Django Debug=True
. 我有一个本地分支, master
和一个带有Django Debug=True
的本地数据库。
I push master
to my server, where there's a live database, and a .env
file with Debug
set to False
. 我将master
推送到服务器,那里有一个实时数据库,以及一个.env
文件,其中Debug
设置为False
。
I've now setup a new local branch - debug
- which has Debug=True
, and using an SSH tunnel, I can connect to my live database. 现在,我已经设置了一个新的本地分支debug
具有Debug=True
,并且可以使用SSH隧道连接到实时数据库。
All I want this for, is to run my code against the live database, with Debug
set to True
. 我要做的只是在Debug
设置为True
针对实时数据库运行我的代码。 So when something breaks on the server, as long as debug
and master
are meaningfully the same apart from the .env
, I should be able to debug whatever is wrong without Debug=TRUE
ever happening on the live, internet facing instance. 因此,当服务器上发生故障时,只要.env
之外的debug
和master
有意义地相同,我就能够调试任何错误,而无需在面对Internet的实时实例上发生Debug=TRUE
的情况。
What I'd like is for my local debug
branch to be an exact replica of master
, in every way, but instead of connecting to my local database, it connects to the live one via SSH tunnel, with and Debug = True
. 我想以各种方式让我的本地debug
分支成为master
的精确副本,但是它不是通过连接到我的本地数据库,而是通过SSH隧道并使用Debug = True
来连接到实时数据库。
I have a .gitignore
file called .env
, and I'm running python decouple
. 我有一个名为.env
的.gitignore
文件,并且我正在运行python decouple
。
My .env
files are referenced in that .gitignore
file. 我的.env
文件在该.gitignore
文件中引用。
There's an .env
for the live server, and one for the local master
branch. 实时服务器有一个.env
,本地master
分支有一个。
I now need a third one for debug
branch - but it's not tracked by Git, so when I switch over branches, it still points at my single .env
file. 现在,我需要第三个分支来进行debug
分支-但是Git不会跟踪它,因此当我切换分支时,它仍然指向我的单个.env
文件。
If I track it, it ends up in the repository defeating the purpose of decoupling. 如果我跟踪它,它最终将在存储库中失效,从而失去了去耦的目的。
So far, I've hard coded the environment variables (database etc) into the settings.py
file of my debug
branch. 到目前为止,我已经将环境变量(数据库等)硬编码到我的debug
分支的settings.py
文件中。
But how do I now move forward? 但是我现在该如何前进?
How can I have debug
the same as master
in every way other than settings.py
? 除了settings.py
如何通过其他方式debug
与master
相同的master
? My .gitignore
is not branch specific? 我的.gitignore
不是特定于分支的吗?
And also, how do I automatically keep debug
synced with master
? 而且,如何自动保持debug
与master
同步?
Ideally, I'd have debug
sync to master
(apart from settings.py
), and then the entire branch just never commits to the repo? 理想情况下,我将debug
同步到master
(除settings.py
),然后整个分支永远都不会提交到存储库?
Is there a better solution to all of this? 是否有更好的解决方案?
Is there a better solution to all of this? 是否有更好的解决方案?
Yes, and it involves keeping (for a given file, here env-dev.txt
) different content based on branches , which means: 是的,它涉及根据分支保留(对于给定文件,在此处env-dev.txt
) 不同的内容 ,这意味着:
env.tpl
仅对模板文件进行版本控制env.tpl
env.dev
, env.master
: since they are different, there is no merge issue when merging or switching branches. 以分支命名的版本值文件: env.dev
, env.master
:由于它们不同,因此合并或切换分支时没有合并问题。 For that, you would register (in a .gitattributes
declaration ) in your submodule repo a content filter driver . 为此,您可以在子模块存储库中注册(在.gitattributes
声明中 ) 内容过滤器驱动程序 。
(image from " Customizing Git - Git Attributes ", from " Pro Git book ") (图片来自“ 自定义Git-Git属性 ”,来自“ Pro Git书 ”)
The smudge
script, associate to the template file ( env.tpl
), would generate (automatically on git checkout
) the actual env
file by looking values in the right env.<branch>
value file. 与模板文件( env.tpl
)关联的smudge
脚本将通过在正确的env.<branch>
值文件中查找值来生成(自动git checkout
)实际的env
文件。 The generated actual env
file remains ignored (by the .gitignore
), as you currently do. 像您当前所做的那样,生成的实际env
文件仍然被忽略( .gitignore
)。
See a complete example at " git smudge/clean filter between branches ". 请参阅“ 分支之间的git smudge /清洁过滤器 ”中的完整示例。
Your smudge
script can determine the name of the checked out branch with: 您的smudge
脚本可以使用以下命令确定已检出分支的名称:
branch=$(git rev-parse --symbolic --abbrev-ref HEAD)
The same idea applies to settings.py
if you need branch-specific content. 如果您需要分支特定的内容,则同样的想法也适用于settings.py
。 ` `
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.