What is the proper use of .gitattributes with merge = ours

I just tried using .gitattributes for the first time. I believe that I should do something wrong, because it does not work, because I thought that the purpose of using the merge=ours attribute is for (?).

An example of my use:

I have two branches; one is the master, and the other is the GCE site. There are files in the "GCE-Site" branch that have different settings, which also exist in the "master" branch, which I do not want to merge with "master" [or other branches].

In both branches I have a .gitattributes containing the following rules:

 README.md merge=ours config.php merge=ours .gitattributes merge=ours .gitignore merge=ours .cache/ merge=ours 

All files requiring rules are at the root level plus everything above the .cache / folder. When I do git merge GCE-Site , all files are merged into master anyway when I don't want it.

Is there something I am missing? Your help is greatly appreciated. Thnx

+8
git merge bitbucket attributes
source share
2 answers

A simple fix when I realized what I was doing: I skipped adding a merge strategy with git config --global merge.ours.driver true in my local environment.

+6
source share

As mentioned in the " .gitattributes and individual merge strategies for the file :

The merge driver is called only in non-trivial cases, i.e. if the wizard and test touched the settings (and you first need to determine the merge driver).

You can see an example of parallel modification (i.e. changes in both branches) in " How do I tell git to always select the local version for conflicting merges in a specific file? ".

So, if your merges did not include modifications of the same files in the 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 the merge driver, but a content filter filter , as in " Save settings in a branch "

content filter driver

This allows you to maintain version control:

  • template file for settings in the cache/ folder
  • a script can take a template file and replace the value of the placeholders with the correct value depending on the output branch.
+2
source share

All Articles