GitLab - 忽略目标分支中的特定文件 [英] GitLab - ignore specific files in target branch

查看:1522
本文介绍了GitLab - 忽略目标分支中的特定文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中使用GitLab,我有一个非常特定的工作流程。我有两个分支 Dev 发布,如下所示。当我提交从Dev到Release的合并请求时,配置文件也将被Dev分支覆盖。





但理想情况下,配置文件必须不同为这两个分支。我试图使用 merge = ours 。但它并没有达到我的目的,因为它不会覆盖,除非在配置文件中有冲突。我不想在 .gitignore 中添加这些文件,因为这些文件的任何更改都不会在 Dev 分支中提交。有人可以请指导我如何实现这一目标?

解决方案

您可以简单地确保您的dev和master的配置文件名称不同,与他们自己的历史。这样,合并不会覆盖任何东西。

b
  • a config.tpl (带占位符值的模板文件)。
  • 两个配置文件,一个用于dev,一个用于master

  • 一个脚本,能够获取配置文件和模板文件,并生成 config 文件(它保持未跟踪,私有)

  • a .gitignore 忽略结果生成的 config 文件

  • a .gitattribute 声明了涂抹内容过滤器(见下文)


    配置文件的生成是通过

    (图片从自定义Git - Git属性 a> from Pro Git book ))



    一旦您在本地配置中声明了内容文件管理器驱动程序,它会自动在 git checkout 上生成 config 文件。

    查看最佳实践 - Git + Build automation - 保持配置不同


    I am using GitLab in my project and I have a quite specific workflow. I have 2 branches "Dev" and "Release" as shown below. When I submit a merge request from Dev to Release, the config files are also getting overwritten with that of Dev branch.

    But ideally config files have to be different for both of these branches. I tried to use merge=ours. But it didn't serve my purpose as it will not override until and unless there is a conflict in config files. I don't want to add these files in .gitignore, as any changes to these files will not be committed in Dev branch. Can someone please guide me how to achieve this?

    解决方案

    You can simply make sure your config files for dev and master are named differently, with their own history. That way, a merge will never overwrite anything.

    You can then version and track:

    • a config.tpl (template file with placeholder values).
    • two config file, one for dev, one for master
    • a script able to take a config file and a template file, and produce the config file (which remains untracked, private)
    • a .gitignore which ignores the resulting generated config file
    • a .gitattribute declaring a smudge content filter (see below)

    The generation of the config file is automated through a content filter driver, using a .gitattributes declaration.


    (image from "Customizing Git - Git Attributes" from "Pro Git book"))

    Once you declare that content filer driver in your local config, it will automatically, on git checkout, generate your config file for you.
    See a complete example in "Best practice - Git + Build automation - Keeping configs separate".

    这篇关于GitLab - 忽略目标分支中的特定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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