10

我有以下目录结构:

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

我的项目使用两个主要分支,master 和 staging,每个分支都跟踪一个不同的远程(生产和登台 heroku 应用程序)。

这个想法是,staging 分支随着新功能向前发展,它们被推送到 staging 远程并在远程进行测试,然后 master 被快速转发以匹配 staging 并推送到生产远程。

这就是我想做的:自由合并这两个分支,同时保持它们的版本braintree.rbproduction.rb分开。

为了做到这一点,这是我输入的内容.gitattributes(根据 ProGit 书):

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

该文件存在于两个分支中。

我遇到的问题是这似乎对任何事情都没有任何影响。每当我在两者之间合并时,文件都会被更改,我必须再次更改它们。

我有一种感觉,我错过了一些非常明显的东西,但到目前为止它正在逃避我。我知道这里的其他答案涉及创建自定义合并驱动程序,但 ProGit 书没有提到这个过程,似乎暗示ours驱动程序是内置的(我已经在手册页中看到它,所以我比较确定)。我唯一能想到的另一件事是我以某种方式放.gitattributes错了地方或弄乱了它的内容,但我找不到太多关于这方面的信息。我尝试将其移动到与文件相同的目录,但无济于事。

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

4

1 回答 1

4

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.

于 2012-04-04T14:14:01.387 回答