简体   繁体   English

我可以忽略整个分支来创建一个与实时服务器连接的本地分支,并将调试设置为True吗?

[英]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之外的debugmaster有意义地相同,我就能够调试任何错误,而无需在面对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来连接到实时数据库。

The problem 问题

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如何通过其他方式debugmaster相同的master My .gitignore is not branch specific? 我的.gitignore不是特定于分支的吗?
And also, how do I automatically keep debug synced with master ? 而且,如何自动保持debugmaster同步?
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不同的内容 ,这意味着:

  • versionning only a template file env.tpl 仅对模板文件进行版本控制env.tpl
  • version value files named after the branches: env.dev , env.master : since they are different, there is no merge issue when merging or switching branches. 以分支命名的版本值文件: env.devenv.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.

相关问题 如何在不更改主分支的情况下更改本地 git 存储库的功能分支? - How do I change a feature branch of a local git repo without changing the master branch? 如何在我的 Pipfile 中指定自定义 Git 分支? - How can I specify a custom Git branch in my Pipfile? 将本地分支推送到远程分支 - Pushing local branch to remote branch pip install -e local git 开发环境分支 - pip install -e local git branch for development environment 如何在我的Git分支的本地副本中使用拉取请求? - How to use a pull request in my local copy of a Git branch? Git Pycharm 仅将本地 master 分支更改为与 origin master 分支完全相同 - Git Pycharm change only the local master branch to be exactly like origin master branch 我有一个代码片段,如果条件为真,它会添加到计数器中。 我怎样才能缩短它? - I have a code snippet that adds to counter if condition is true. How can I shorten it? 如何根据逻辑创建布尔系列:(0 后跟 1 为真。1 前为 0 为真。所有其他都是假) - How to create a Boolean Series based on the logic: (0 followed by a 1 is True. A 1 preceded by a 0 is True. All others are False) 将旧分支合并到新分支GIT - Merge old branch to new branch GIT 我有一个链接的 trie 返回 false 而不是 true。 可以修复代码中的哪些错误? - I have a linked trie returning false instead of true. What errors can be fixed in the code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM