有条件的 Mercurial 忽略文件
我在 Mercurial 中有一个文件,我希望开发机器提取该文件,但我希望部署服务器不提取该文件(它具有开发机器没有的特殊模块)。这是可能的,还是我应该有一个自定义的推送到服务器解决方案,而不是仅仅执行 hg pull ?
I have a file in mercurial that I want dev machines to pull the file, but I want the deployment server to NOT pull the file (it has special mods to it that the dev machines don't have). Is this possible, or should I just have a custom push to server solution instead of just doing an hg pull?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
执行此操作的典型方法是执行以下操作:
将每个文件的副本存储在存储库中,并正确命名它们。例如,如果相关文件是
web.config
,您将在存储库中存储以下两个文件:web.server.config
web.dev.config
然后您将添加一个构建步骤以确保将正确的文件复制到实际的
web.config
文件中,您可以使用批处理文件:然后您将通过 忽略 web.config 本身。赫吉诺尔:
A typical way to do this would be to do the following:
You store a copy of each file in the repository, and name them correctly. For instance, if the file in question is
web.config
, you would store the following two in the repository:web.server.config
web.dev.config
Then you would add a built step to ensure the right file was copied to the actual
web.config
file, you could use a batch file:Then you would ignore web.config itself through .hgignore:
我经常使用卡尔森答案的一个变体。
我的项目中有
/config
或/etc
目录。该目录通常包含示例配置,例如:dev.yaml
ci_server.yaml
然后我的应用程序从
/etc/app.yaml
中提取,这是一个符号链接到正确的配置,具体取决于正在运行的主机。这样做的最佳考虑是您没有变体代码路径(批处理脚本分支),这消除了潜在的错误向量。这允许您执行将在生产中使用的相同代码路径(直至查找覆盖文件的位置)。
A variant of Karlsen's answer that I always use.
I have
/config
or/etc
directory in the project. That directory will often contain sample configs like:dev.yaml
ci_server.yaml
Then my apps pull from
/etc/app.yaml
which is a symlink to the correct config depending on the host it's being run on.The best think about doing it this way is you don't have variant code paths (the batch script branches) which eliminates a potential bug vector. This allows you to exercise the same code path that will be used in production (down to where to look for the override file).
这是可以在版本控制之外解决的问题吗?例如,将该文件包含在存储库的所有副本中,但通过环境变量或类似变量启用或禁用其使用。这听起来不像大多数版本控制系统都是为了处理的事情,除非您在更新后使用令人讨厌的黑客来执行诸如添加/删除/修补文件之类的操作。
Is this something that can be solved outside version control? For instance, include the file in all copies of the repository, but enable or disable its use with environment variables or something similar. This doesn't sound like something most version control systems are built to handle, unless you use nasty hacks to do things like add/remove/patch files after updating.
一种选择是为部署服务器创建一个特殊的 hgignore 文件,该文件可以或无法包含在存储库中。然后在服务器的 hgrc 文件中使用 < 指定特殊 hgignore 文件的路径代码>忽略变量。
这将确保部署服务器会忽略对文件的更新,但仍可以像往常一样对开发计算机进行更新。
One option is to create a special hgignore file for the deployment server, that could or could not be included in the repository. Then in the server's hgrc file specify the path to the special hgignore file with the
ignore
variable.This would ensure that updates to file would be ignored by the deployment server but could still be updated as usual for the development machines.