有条件的 Mercurial 忽略文件

发布于 2024-10-09 02:13:39 字数 118 浏览 7 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

墟烟 2024-10-16 02:13:39

执行此操作的典型方法是执行以下操作:

将每个文件的副本存储在存储库中,并正确命名它们。例如,如果相关文件是 web.config,您将在存储库中存储以下两个文件:

  • web.server.config
  • web.dev.config

然后您将添加一个构建步骤以确保将正确的文件复制到实际的 web.config 文件中,您可以使用批处理文件:

if "%COMPUTERNAME%" == "SERVER" copy web.server.config web.config
if not "%COMPUTERNAME%" == "SERVER" copy web.dev.config web.config

然后您将通过 忽略 web.config 本身。赫吉诺尔:

glob: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:

if "%COMPUTERNAME%" == "SERVER" copy web.server.config web.config
if not "%COMPUTERNAME%" == "SERVER" copy web.dev.config web.config

Then you would ignore web.config itself through .hgignore:

glob:web.config
千纸鹤带着心事 2024-10-16 02:13:39

我经常使用卡尔森答案的一个变体。

我的项目中有 /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).

半夏半凉 2024-10-16 02:13:39

这是可以在版本控制之外解决的问题吗?例如,将该文件包含在存储库的所有副本中,但通过环境变量或类似变量启用或禁用其使用。这听起来不像大多数版本控制系统都是为了处理的事情,除非您在更新后使用令人讨厌的黑客来执行诸如添加/删除/修补文件之类的操作。

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.

献世佛 2024-10-16 02:13:39

一种选择是为部署服务器创建一个特殊的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文