How to use git merge driver, union?

Viewed 411

We have a staging environment that auto-merges new branches into our staging branch and deploy our website on a staging server.

A new branch is based off our current master branch and then auto-merged into staging with git merge -X ours [new branch]. We got two files where we want to have a union merge. Meaning that, all changes from a branch must be copied wholly into a file.

So I have added those two files to .gitattributes:

allCampaigns.json merge=union
f-hero.css merge=union

I thought that git merge -X ours would apply to all files except allCampaigns.json and f-hero.css but that is not the case. In the case of allCampaigns.json, new JSON is overwriting another branch JSON, in the case of git merge -X theirs and omitted completely in the case of git merge -X ours.

Just for testing, I don't want a union merge for all files, I tried git merge -X union but that gives me a fatal error: fatal: Unknown option for merge-recursive: -Xunion.

This, git merge, keep both, SO question is exactly what I want but the answer is to add merge=union in .gitattributes which I have done but it is not working.

I'm using git version 2.30.2 and our server (which does the merging) is using git version 2.25.1 - both are linux machines.

It is almost as union merge does not exist.

How am I suppose to use the union merge driver?

File Overview

Below is a simplified overview of the website files. It shows files and folders at the root level, plus the location of f-hero.css.

.
├── .editorconfig
├── .git
├── .gitattributes
├── .gitignore
├── AWS_S3/
├── Makefile
├── README.md
├── allCampaigns.json
├── allCampaigns.schema.json
├── app.js
├── bin/
├── config/
├── node_modules/
├── package-lock.json
├── package.json
├── post-mortem.md
├── public/
├── server/
├── spec/
├── styles/
│   ├── base.css
│   └── blocks/
│       ├── f-hero.css
│       └── f-white-card.css
├── tools/
└── views/
0 Answers
Related