版本控制机器特定配置
我想在多个地点工作,例如在一个网站上。 每台电脑都有自己的项目存储库(最好是 Mercurial,否则是 Git),但每台计算机都需要自己的配置设置来进行本地测试,例如 base_url。 对该配置文件(也包括全局配置设置)进行版本控制的最佳方法是什么?
存储库详细信息:
- BitBucket 上的 Repo,带有 config.php:全局配置 + 实时服务器的配置
- Repo pc A 带有 config.php:全局配置 + 特定于 PC A 的配置
- Repo pc B 带有 config.php:全局配置 + 特定于 pc B 的配置
当我签出 BitBucket 存储库时,我获得了完整的实时服务器配置。如果我需要进行调整并在本地进行测试,我会将实时设置更改为电脑特定的设置。然后修复错误或其他任何问题,提交并推送到 BitBucket。 此时,PC 特定设置将被推送到全局 BitBucket 存储库:不是我想要的。
那么正确完成此操作的最佳方法是什么?
I want to work from several locations on -for instance- a website.
Every pc has its own repository of the project (preferably Mercurial, Git otherwise), but each computer needs its own config settings for testing locally, like base_url.
What is the best way of versioning this config file which will include global config settings as well?
Repository details:
- Repo on BitBucket with config.php: global config + config for live server
- Repo pc A with config.php: global config + config specific for pc A
- Repo pc B with config.php: global config + config specific for pc B
When I checkout BitBucket repository I get the full live server configuration. If I need to make adjustments and test it locally, I change the live settings to the pc specific settings. Then fix a bug or whatever, commit and push to BitBucket.
At this moment the pc specific settings will get pushed to the global BitBucket repo: not what I want.
So what's the best method to get this done properly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要的是一个污迹清理脚本,该脚本可以根据您所在的机器更改配置。
https://git-scm.com/docs/gitattributes
https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes#_keyword_expansion
如果您想在单独的分支中跟踪每台电脑的配置,请对配置,然后将您的更改合并到您在公共远程中公开的分支中,但忽略您的更改
从现在开始,您可以从分支合并,但您的配置更改永远不会被合并,因为它已经被考虑已根据 DAG 进行合并。
希望这有帮助。
What you need is a smudge clean script that changes the config depending on what machine you are on.
https://git-scm.com/docs/gitattributes
https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes#_keyword_expansion
If you want to track each PC's config in a separate branch, do the change to the config, then do a merge of your changes into the branch you have exposed in the common remote, but ignoring your change
From now on you can merge from your branch but your config change won't ever be merged as it is already considered having been merged according to the DAG.
Hope this helps.
我对 php 不太熟悉,但我假设您可能有一个全局 config.php 文件,其中可能包含(需要?)
config..php
文件。这样所有的配置文件都将受到版本控制,但不会有冲突。 PHP 应该有某种方法来确定当前计算机的主机名,然后加载适当的配置文件。生成的存储库布局可能如下所示
I'm not very familiar with php, but I assume you could have a global config.php file which could include (require?)
config.<hostname>.php
files. This way all the config files would be under version control, but there would be no conflicts. PHP should have some way of determining the hostname of the current machine and then loading the appropriate config file.The resulting repository layout might look like this
我会将 config.php 设计得透明。存储库本身不必关心它在什么环境中运行。我不知道您需要更改什么才能在您的情况下启动并运行它,但也许将 config.php 中的功能提升到一些设置中,这些设置又由 config.php 读取。
I would design config.php to be transparent. The repository itself shouldn't have to care about in what environment it's running on. I don't know what you need to change in order to get this up and running in your case, but perhaps lift out functionality from your config.php into some settings that is in turn read by config.php.