2

I want to use merge=ours for a specific file. So I added this to .gitattributes file:

.eslintcache merge=ours

But as stated here, I have to run git config --global merge.ours.driver true. But I want this to be enabled for all contributors in the repo.

Also, I don't understand why the page calls it "a dummy ours merge strategy"! while in this page it seems to be a predefined strategy. Shouldn't it just work without adding this config?

Vahid
  • 6,639
  • 5
  • 37
  • 61
  • 1
    If I understand it correctly, you can't. The driver has to be enabled on each environment. See https://stackoverflow.com/questions/47112822/push-git-config-file-settings-to-remote-url – fredrik Jan 01 '22 at 19:47

1 Answers1

2

You can't do this because in order to make the option work, it requires configuration, and Git doesn't permit sharing configuration because that would permit arbitrary code execution. For example, if instead of true, you wrote rm -fr ~, then anytime that merge driver was invoked, it would remove the user's home directory.

You can provide a script which users can use to set up their environment, which can set up this configuration, and many projects provide such a script. However, you cannot force a user to run this script or set up this configuration.

If you need this merge strategy to happen automatically, you can perform all merges to the repository with a bot, and then all merges will use the configuration you desire.

bk2204
  • 64,793
  • 6
  • 84
  • 100
  • 1
    Thanks. But how can I use this option in a gitlab merge request? I wanna prevent merge conflicts for a specific file – Vahid Jan 02 '22 at 06:53
  • Also just to make sure I understood correctly, the Git strategies that are explained in the docs, aren't available to the gitattributes file and are just the options of `git merge` command, right? – Vahid Jan 02 '22 at 07:00
  • 1
    You can't use it in a GitHub or GitLab merge request at all. You could have a bot that merged those PRs automatically, but if you use the merge button, then it won't take effect. And no, the built-in merge strategies are not supported automatically as options. – bk2204 Jan 02 '22 at 16:39