添加一个git合并驱动程序到存储库? [英] Add a git merge driver to the repository?

查看:116
本文介绍了添加一个git合并驱动程序到存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个合并驱动程序。我已经定义了一个.gitattributes文件,如下所示:

filename merge = mergeStrategy



我已经在$ PROJECT / .git / config中创建了合并驱动程序,如下所示:

  [merge mergeStrategy] 
name =我的合并策略
driver = scripts / mergeScript.sh

这在本地运行良好,但我想将此合并驱动程序提交到git存储库,以便合并策略适用于所有人。



有没有我可以添加这个(或其他Git配置选项)到存储库本身吗?

解决方案

您可以简单地添加和提交(和推送) script / mergeScript (当然还有 .gitattributes 文件)



只要:


  • mergeScript 以某种方式执行合并驱动程序的用户 $ PATH 中。

  • mergeScript 是可执行文件, chmod + x

  • mergeScript 没有扩展名,允许您稍后改变它的内容(从bash shell到Perl脚本到C如果需要的话,可执行文件...)。

    $ b

    (谢谢, MestreLion ,最后两点,就像他在评论中提到的那样)



    那是在你的本地情况下,因为我怀疑''在你的 $ PATH 中,但你不能假设对于每个人。



    但是,本地配置文件( .git / config )不会推送/克隆(如亚历山大Priymak 在评论中指出),所以用户仍然需要复制自定义合并驱动程序的声明。

    这是一个基本的安全措施,为了您不需要推出潜在的有害脚本,然后在下一次合并时自动执行。

    I'm creating a merge driver. I have defined a .gitattributes file as follows:

    filename merge=mergeStrategy

    I have created the merge driver in $PROJECT/.git/config as follows:

    [merge "mergeStrategy"]
        name = My merge strategy
        driver = scripts/mergeScript.sh
    

    This works fine locally, but I would like to commit this merge driver to the git repository so that the merge strategy is in effect for everyone.

    Is there a way I can add this (or other Git configuration options) to the repository itself?

    解决方案

    You could simply add and commit (and push) script/mergeScript (along with the .gitattributes file, of course)

    That would work as long as:

    • mergeScript is somehow in the $PATH of the user executing the merge driver.
    • mergeScript is executable, chmod +x
    • mergeScript is without extension, to allow you to later change its content (from a bash shell to a Perl script to a C executable to ...) if needed.

    (Thank you, MestreLion, for the last two points, as he mentioned them in the comment)

    That was the case for you locally, as I suspect that '.' was in your $PATH, but you cannot assume that for everybody.

    However, the local config file (.git/config) won't be pushed/cloned (as Alexandr Priymak points out in the comment), so the users still need to replicate the declaration of the custom merge driver.
    This is a basic safety measure, in order for you to not push a potential "harmful" script which would then be automatically executed at the next merge.

    这篇关于添加一个git合并驱动程序到存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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