每个分支中静态配置文件的git合并策略 [英] git merge strategy for static config file in each branch

查看:243
本文介绍了每个分支中静态配置文件的git合并策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要一种系统的方式来忽略我们在git上维护的分支的特定配置文件.

We need a systematic way of ignoring a specific config file for the branches we maintain on git.

即我们有一个config.xml文件,其中包含数据库,环境以及跨'develop'和'master'分支的其他信息,我们希望将它们排除在'git merge'的结果之外.

i.e. we have a config.xml file with database, environment, and other info across 'develop' and 'master' branches that we'd like to keep out of the outcomes of 'git merge'.

我们遵循了SCM书中的合并策略说明,但是当执行分支合并时,git似乎仍在合并config.xml:
http://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes#Merge-Strategies

We followed the SCM book instructions for merge strategies, but git still seem to be merging config.xml when we do branch merges:
http://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes#Merge-Strategies

我也看过这篇SO帖子,它需要程序员有意识的努力来有选择地忽略config.xml文件-似乎很容易出错:
每个git分支中的不同配置

I've also had a look at this SO post which require conscious programmer effort to selectively ignore the config.xml file - seem to be prune to error:
Different configs in each git branch

还有这样的SO帖子,它解释了除ours之外的其他git合并策略,其他似乎都不符合我们的目的:
何时使用不同的git合并策略?

There's also this SO post which explains the different git merge strategies, other than ours, none of the others seem to suit our purpose:
When would you use the different git merge strategies?

我很好奇,你们用什么方法来控制对配置文件的更改,这些更改在每个分支中都保持一致,而不会弄乱"git merge"呢?

I'm curious what methods you guys use to control the changes to config files that stays pretty consistent in each branch without having 'git merge' mess things up?

推荐答案

合并驱动程序(如我们的"策略)的问题是,正如我在".git属性和文件的单独合并策略":

The issue with a merge driver (like an "ours" strategy) is, as I mentioned in ".gitattributes & individual merge strategy for a file":

仅在非平凡的情况下才调用合并驱动程序,即,如果主设备和测试都已触及设置(并且您需要首先定义我们的合并驱动程序).

The merge driver is only called in non-trivial cases, i.e. if both master and test have touched setup (and you need to define the merge driver ours first).

我在"我如何告诉git始终为特定文件上的冲突合并选择本地版本时使用了这样的策略?",但确实在两个分支中都进行了修改.

I used such a strategy in "How do I tell git to always select my local version for conflicted merges on a specific file?", but it did involved a modification in both branches.

对于某些具有不同设置的文件,另一个选项是内容过滤器驱动程序,如"保留分支中的设置"

For some files with different settings, another option would be a content filter driver, as in "Keep settings in branch"

("自定义Git-Git属性",来自" Pro Git书 )

(image shown in "Customizing Git - Git Attributes", from "Pro Git book")

这使您可以保持版本控制:

That allows you to keep in version control:

    设置文件本身的
  • 模板文件,其中带有占位符部分(例如@@PORT@@)
  • 一个脚本,该脚本可以获取模板文件,并根据签出的分支或内容将值占位符替换为正确的值.
  • 多个值文件,以便针对不同的上下文版本正确的值.
    由于这些文件的命名不同,并且仅在其各自的分支中进行了修改,因此它们不参与合并.
  • template file for the settings file itself, with placeholder sections in it (like @@PORT@@)
  • a script able to take a template file and replace the value placeholders with the right value depending on the branch checked out or the content.
  • multiple value files in order to version the right values for different context.
    Since those files are named differently and only modified in their respective branch, they are not involved in a merge.

这篇关于每个分支中静态配置文件的git合并策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆