.gitattributes&个别文件合并策略 [英] .gitattributes & individual merge strategy for a file

查看:229
本文介绍了.gitattributes&个别文件合并策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的(网络)应用程序的主人和测试分支。这些项目几乎是相同的,除了一个设置应用程序的文件,比如说setup。



每当我将一个分支合并到另一个分支时,我希望分支以保持其版本的设置。也就是说,git不应该试图将更改合并到该文件中。



我遵循 Pro Git书籍的指导并创建一个.gitattributes文件,其中包含setup merge = ours这一行。但是,这不起作用 - 如果我引入冲突,那么快速前进合并不会。



<准确地说:

  $:mkdir gitest 
$:cd gittest
$:git init
$:echosetup merge = ours>>。 gitattributes
$:echomaster>> setup
$:git add setup .gitattributes
$:git commit -a -m ...
$:git branch测试
$:git checkout test
$:echotest>> setup
$:git commit -a -m ...
$:git checkout master
$:git merge test

预期结果:setup包含单词master,而不是git )

解决方案

我有同样的错误,它可以解决只是定义一个我们的合并驱动程序在.git / config中:

  [合并我们的] 
name =保留我们的合并
driver = true

因为true总是返回0临时文件ho lding目前的状态将不会改变,并将保持最终版本。



您可以在这里阅读更多关于合并驱动程序的信息: http://www.kernel.org/pub/software/scm/git/docs/gitattributes。 html#_defining_a_custom_merge_driver



附录:

在任何时候驱动程序实际被调用时,似乎只有在提交更改相同文件(git merge属性)时才会发生。如果一个分支有变化,司机不会被叫。


I have a master and a test branch of my (web) application. These projects are almost the same, except for one file which sets up the application, say "setup".

Whenever I merge one branch into the other, I would like that branch to keep its version of setup. That is, git should not attempt to merge the changes to that file.

I followed the guidance from the Pro Git book and created a .gitattributes file, with the line "setup merge=ours". However, this does not work - neither with fast forward merges not if I introduce conflicts.

(To be precise:

$: mkdir gitest
$: cd gittest
$: git init
$: echo "setup merge=ours" >> .gitattributes 
$: echo "master" >> setup
$: git add setup .gitattributes
$: git commit -a -m ...
$: git branch test
$: git checkout test
$: echo "test" >> setup
$: git commit -a -m ...
$: git checkout master
$: git merge test

Expected result: setup contains the word "master", instead git performs a ff merge and setup is "test'.)

解决方案

I had the same error and it can be solved just defining an "ours" merge driver in .git/config:

[merge "ours"]
    name = "Keep ours merge"
    driver = true

Since true always return 0 the temporary file holding the current state will not be changed and will stay as the final version.

You can read more about merge driver in here: http://www.kernel.org/pub/software/scm/git/docs/gitattributes.html#_defining_a_custom_merge_driver

Addendum:

This works any time the driver is actually called and this seems to occur only when there are commits changing the same files (git the merge attribute). If there are changes in a single branch the driver is not going to be called.

这篇关于.gitattributes&amp;个别文件合并策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆