1

I am using Sourcetree 3.0.12 on Windows. The command-line git version I'm using is git version 2.18.0.windows.1 (at least that's what it says when I open the Terminal from Sourcetree and get the Cygwin command line).

I want all the files on app/Resources/ in my tree to be "protected" from changes in other branches; in other words, I want git to always merge my version in that folder. So I did the following:

1) In the command line, at the root of the tree, I typed git config --global merge.ours.driver true.

2) At the root of my tree I created a .gitattributes file that said:

app/Resources/ merge=ours

Then I try to merge a change in another branch... and I get a lot of conflicts in files in app/Resources.

I read around an offhand comment suggesting that this feature only works with a newer version of git. Is that the case, or did I do something wrong?

EDIT: following the first answer below, I edited by hand my .git/config file to add this:

[merge "ours"]
    name = ours
    driver = true

I added it at the end of the file, then I tried merging again... but didn't work either.

PaulJ
  • 1,646
  • 5
  • 33
  • 52

2 Answers2

1

Looks like you are trying to define a custom merge driver there. The docs tell that you should do this in another file, then reference it. This holds even in version 2.18.0.

The definition of a merge driver is done in the .git/config file, not in the gitattributes file, so strictly speaking this manual page is a wrong place to talk about it. ref

If I have a look at the examples, I see that:

ab* merge=filfre
abc -foo -bar
*.c frotz

Where that filfre was defined in the git config file. This should at least address the part 2 of your question, I'd advice you to try this different approach there.

For part 1, git config --global merge.ours.driver true was given as accepted answer here, although I feel like the other answer is way more accurate. Indeed, the accepted answer is by the original question author, and doesn't provide much inside. A known corner case is also available where the fix doesn't work. Have you considered the alternative approach?

Daemon Painter
  • 3,208
  • 3
  • 29
  • 44
  • You mean using content filters? That doesn't really work in my case, I think. The two branches have two sets of templates for different websites that share one backend engine; in other words, there are too many different files for that to work (at least if I understand the feature...) – PaulJ Jun 15 '20 at 15:21
0

You should add

app/Resources/* merge=ours

in your .gitattributes.

Adriaan
  • 17,741
  • 7
  • 42
  • 75
Erwan Leroux
  • 108
  • 2
  • 11