herrmartell
herrmartell

Reputation: 3117

Alternative to .gitattributes

I've been searching for a way to merge a branch into another without overriding image & css folders. I looked up around SO and found some questions and answers mentioning .gitattribute.

I also checked out the official documentation.

But I must be missing something, because every time I try to do a merge (between two branches where I have replaced images) I get a merge conflict.

For reference, this is my .gitattributes file, included in both branches:

/res/icon/                 merge=ours
/res/screen/               merge=ours
/platforms/                merge=ours
/www/assets/css/           merge=ours
/www/background_splash.png merge=ours
/www/bglogin.png           merge=ours
/www/top_bar.png           merge=ours

Am I missing something here? Thanks.

Also, is there another option for me to achieve this?

Upvotes: 0

Views: 134

Answers (1)

torek
torek

Reputation: 487883

If you want all files within res/icon, you need either:

/res/icon/*                merge=ours

(if there are no subdirectories) or:

/res/icon/**/*             merge=ours

(if there are subdirectories). Repeat this pattern for all directories.

But note that there is a flaw: the ours merge driver will only be used if there is something to combine. That is, suppose there a file named res/icon/foo.img. In the merge base commit, this is an image of the letter B for Base. In your branch, this is still an image of the letter B, bit-for-bit identical to the original file. In their branch, this is a different image, or a different color, or whatever, so that the file is not bit-for-bit identical.

Running git merge theirs, your Git will compare the base B in res/icon/foo.img to your B, see that they are the same, compare the base B to their image, see that they are different, and choose their file because there is nothing to resolve.

If you did change the file in any way, Git compares the base res/icon/foo.img B to your res/icon/foo.img file (maybe your B is now a different color). Git compares the base B to their file. Both you and they have changes, so there are different changes to combine. Now Git will use your merge=ours driver to achieve the combining.

(Git probably should have a flag, "merge driver must always be used" or some such, to force it to use your driver even if Git thinks there are no changes to combine. But Git does not have such a flag today.)

Upvotes: 1

Related Questions