Whats the Proper usage of .gitattributes with merge=ours

前端 未结 2 730
傲寒
傲寒 2020-12-06 05:59

I just tried using .gitattributes for the first time. I figure I must be doing something wrong because it is not working as I thought the purpose of using the merge=o

相关标签:
2条回答
  • 2020-12-06 06:11

    As 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).

    You can see an example of concurrent modification (ie modification in both branches) in "How do I tell git to always select my local version for conflicted merges on a specific file?".

    So if your merges didn't involve modifications of the same files within cache/ folder in both branches, your merge driver was never called.

    But in your case, for files with different settings, I would recommend not using a merge driver, but a content filter driver, as in "Keep settings in branch"

    content filter driver

    That allows you to keep in version control:

    • template file for the settings in the cache/ folder
    • a script able to take a template file and replace the value placeholders with the right value depending on the branch checked out.
    0 讨论(0)
  • 2020-12-06 06:25

    Easy fix once I knew what I was doing: I missed adding the merge strategy with git config --global merge.ours.driver true in my local environment.

    0 讨论(0)
提交回复
热议问题