gitattributes not setting merge driver correctly

时间秒杀一切 提交于 2020-01-22 18:50:31

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/8266672/gitattributes-not-setting-merge-driver-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!