告诉git在特定文件上使用我们的合并策略 [英] tell git to use ours merge strategy on specific files

查看:237
本文介绍了告诉git在特定文件上使用我们的合并策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下目录结构:

pre $ g $ b $ git / info / attribute
/ MyProject
/MyProject/pom.xml
/MyProject/MyCode.java

我有分支大师和bugfix。在这两个分支上都修改了pom.xml和MyCode.java。
i希望将bugfix中的更改合并到仅用于MyCode.java的主文件中,并保留pom.xml文件的主版本。

所以我添加了/ git / info / attributes,因为我不想在项目中提交.gitattributes
$ b $ $ $ $ $ $ $ $ $ $ $ $ .git / info / attributes
pom.xml merge = our
$ git status
#在分支master上
没有提交(工作目录干净)
$ git check-attr -a pom。 xml
pom.xml:merge:our

最后到问题:



当我这样做时:

  $ git合并bugfix 
自动合并MyProject / pom.xml
CONFLICT(内容):在MyProject / pom.xml中合并冲突
自动合并失败;修复冲突,然后提交结果。

Git忽略属性设置。我在这里错过了什么?



我不想根据这个 post



this 帖子是我需要的,然而,如果我有一个简单的模式,我宁愿不去文件归档



谢谢!

解决方案

  $ git config merge.ours.driver true 

甚至是

  $ git config --global merge.ours.driver true 

'我们的'并不是内置的合并驱动程序,尽管它对您和我来说完全清楚它应该做什么,以及看起来git没有错误,当一个自定义的合并驱动程序是未定义的。



true unix true 命令,它的成功cess说它使得本地版本看起来是正确的,在这种情况下,不做任何事情。)


I have the following directory structure:

/.git
/.git/info/attributes
/MyProject
/MyProject/pom.xml
/MyProject/MyCode.java

I have branch master and bugfix. On both branches pom.xml and MyCode.java were modified. i would like to merge changes from bugfix to master only for MyCode.java and keep master version of pom.xml file.

So I added "/.git/info/attributes" because i don't want to commit .gitattributes with the project

$cat .git/info/attributes
pom.xml merge=ours
$git status
# On branch master
nothing to commit (working directory clean)
$git check-attr -a pom.xml
pom.xml: merge: ours

Finally to the problem:

When I do:

$git merge bugfix
Auto-merging MyProject/pom.xml
CONFLICT (content): Merge conflict in MyProject/pom.xml
Automatic merge failed; fix conflicts and then commit the result.

Git is ignoring attributes setting. What am i missing here?

I prefer not to define "keepMine.sh" per this post

this post is what i need, however i prefer not to go file by file if i have a simple pattern

thanks!

解决方案

$ git config merge.ours.driver true

or even

$ git config --global merge.ours.driver true

'ours' isn't one of the built-in merge drivers even though it's perfectly clear to you and me what it should do, and it seems git doesn't error out when a custom merge driver is undefined.

(true above is just the unix true command, its success says it made the local version look right, in this case by doing nothing to it.)

这篇关于告诉git在特定文件上使用我们的合并策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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