Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gitattributes not setting merge driver correctly

I have the following directory structure:

project/
    .git/
        ...
    app/
        ...
    config/
        initializers/
            braintree.rb
        environments/
            production.rb
    .gitattributes

My project uses two main branches, master and staging, each tracking a different remote (production and staging heroku apps).

The idea is that the staging branch moves forward with new features, they get pushed to and tested on the staging remote, then master is fast-forwarded to match staging and pushed to the production remote.

Here's what I want to do: freely merge these two branches while keeping their versions of braintree.rb and production.rb separate.

To accomplish this, here is what I put in .gitattributes (as per the ProGit book):

config/initializers/braintree.rb merge=ours
config/environments/production.rb merge=ours

The file is present in both branches.

The problem I'm encountering is that this doesn't seem to have any effect on anything. Whenever I merge between the two, the files get changed anyway and I have to go change them again.

I have a feeling I'm missing something horribly obvious, but so far it's escaping me. I know that other answers here have involved creating custom merge drivers, but the ProGit book makes no mention of this process and seems to imply that the ours driver is built in (and I've seen it mentioned in the man pages, so I'm relatively sure it is). The only other thing I can think of is that I've somehow put .gitattributes in the wrong place or messed up its contents, but I can't find much information on that. I've tried moving it to the same directory as the files, but to no avail.

In case it's of any help, I'm running git version 1.7.2 on OS X. Any help would be much appreciated.

like image 690
Luke Avatar asked Nov 25 '11 08:11

Luke


1 Answers

There are two excellent Stack Overflow responses which address this problem:

How do I tell git to always select my local version for conflicted merges on a specific file?

and

.gitattributes & individual merge strategy for a file

I'd suggest reading through the top answer in the first link. It's long, but very detailed and informative.

like image 129
ulmangt Avatar answered Nov 07 '22 16:11

ulmangt