Add a git merge driver to the repository?

白昼怎懂夜的黑 提交于 2019-11-27 17:34:17

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/8839496/add-a-git-merge-driver-to-the-repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!