git - Merge 分支时,如何保持指定的文件不被 Merge?
高洛峰
高洛峰 2017-04-28 09:06:32
0
1
1009

就像SO上这个问题描述的场景: http://stackoverflow.com/questions/928646/how-do-i-tell-git-to-always-select-my-local-version-for-conflicted-merges-on-a-sp

有两个分支,每个分支使用不同的配置,例如:

config.txt (on release branch):
database = 10.9.8.7

config.txt (on develop branch):
database = 192.168.0.1

当需要把develop分支的功能合并到release分支时,不希望config文件被合并;
有以下几种解决方案:

  1. 使用merge strategy;创建一个merge driver,对指定的文件使用指定的merge strategy;
    缺点:文件无改动时,merge driver不会启动,还是会被合并;rebase不管用;
  2. 提交时,使用assume-unchanged;
    缺点:提交时需要时刻关注文件改动;
  3. 使用subtree(submodule)

不知道大家有没什么建议?

参考: http://stackoverflow.com/questions/928646/how-do-i-tell-git-to-always-select-my-local-version-for-conflicted-merges-on-a-sp

http://stackoverflow.com/questions/2250040/using-github-to-host-public-git-repositories-whilst-ensuring-that-sensitive-data#

http://blog.miniasp.com/post/2014/12/23/Git-Advanced-Assume-Unchanged-Skip-worktree.aspx

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(1)
过去多啦不再A梦

It is easier to maintain configuration files for different environments if they are placed in different files

//config.txt
#默认生产环境
database = 10.9.8.7

//config.dev.txt
#开发环境
database = 192.168.0.1

//config.test.txt
#测试环境
database = xxx

Make environment judgment in the code (common methods include IP, hostname, environment variables, etc.) and read different configurations respectively

A further solution is to have a configuration center responsible for issuing configurations, and a garrison elf responsible for finding the configuration center to pull configurations, cache configurations, and cooperate with the center to update configurations, etc.

In short, I personally feel that maintaining the configurations of different environments through different branches will get half the result with half the effort... If you add a test environment, a pre-release environment, and maybe even a unit test environment, a sandbox environment, etc., if you still use branches for more than 3 different configurations If you maintain it, it will basically collapse... If you must do it, I recommend imitating itphpunit.xml.dist的形式,gitignore掉config.txt,然后维护正式的config.txt.dist,代码里优先读config.txt,然后读config.txt.dist

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template