通过自动合并所有更改来解决特定文件的git冲突 [英] resolve git conflicts for particular files by automatic merge all changes

查看:358
本文介绍了通过自动合并所有更改来解决特定文件的git冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个使用github仓库的项目。在合并拉取请求之前有冲突要分解时,大约90%的冲突事件只涉及一个包含已完成工单清单的 CHANGELOG 文件,例如:

  ## current b 
$ b << HEAD
ISSUE-128完成了一些128
ISSUE-131完成了一些131
=======
ISSUE-125完成了一些125
>> >>>>> ISSUE-125
ISSUE-126完成了126
ISSUE-120完成了一些126
ISSUE-123完成了一些126

我想知道是否有一种方法来自动合并这个特定的文件(可能通过提供一些使用ie gitignore格式的配置)和一个简单的规则来接受来自双方的变化至于它的顺序足以让变化紧挨着,知道怎样才能控制顺序是次要的但有趣的)。额外的规则可能是验证每边是否总是只有一个加法,然后才进行自动合并。



理想的情况是在github上有这样的配置,但即使是本地的git解决方案也是有帮助的。

方案

[回答,从评论略微修改。]



这里你想要的通常称为 union merge ,这实际上内置于Git中。它很少做正确的事情,但对于这种特殊情况,union merge实际上可能是正确的。您可以使用 .gitattributes 设置特定文件名的联合合并。有关详情,请参见 git merge,keep both


其实我唯一担心的唯一问题是,对于一个更复杂的冲突,我宁愿看到有冲突要合并


正确:我认为union merge的主要问题是它始终成功,即使合并结果是无意义的。你需要记住它是这样设置的,并且要小心每次检查合并结果。



(个人而言,如果所有这些都会更快乐,那么if Git把它分解成了一个可以在每个文件上调用的单独的resolve命令,我认为 git merge-file 命令实际上大部分是这里所要的,除了它是一个痛苦的使用。一个更可用的接口,而不是 -X我们 -s我们 -X他们等等,以及 .gitattributes 中的各种合并驱动程序,我们可以让合并冲突发生,检查他们,决定哪些方面要保留,如果这样做足够的话,那就去吧。当然,如果一个人走得更远,那么最终会得到一个GUI合并工具...)


There is a project using github repositories. When there are conflicts to be resoled before merging pull request some 90% of conflict cases concern just one CHANGELOG file containing list of completed tickets, sth like:

## current

<<<<<<< HEAD
ISSUE-128 done some 128
ISSUE-131 done some 131
=======
ISSUE-125 done some 125
>>>>>>> ISSUE-125
ISSUE-126 done some 126
ISSUE-120 done some 126
ISSUE-123 done some 126

I wonder if there is a way to automate merge of this particular file (possibly by providing some configuration using i.e. gitignore format) with a simple rule to just accept the changes from both sides (as for the order its enough that the changes will be just next to each other, knowing how could be possible to control the order is secondary yet interesting). Additional rule could be to verify if there is always just one addition on each side and only then proceed with the automatic merge.

Ideally would be to have such configuration on github yet even local git solution would be helpful.

解决方案

[Answer, slightly modified from comments.]

What you want here is usually called union merge, and this is actually built in to Git. It rarely does the right thing, but for this particular case, union merge is actually probably correct. You can set union merge for a particular file name using .gitattributes. See git merge, keep both for more about this.

Actually the only thing I'm still somehow worry about is that for a "more complex" conflicts I'd rather see that there is conflict to merge

Right: the main problem with union merge, I think, is that it always succeeds, even if the merge result is nonsensical. You need to remember that it is set up this way, and be careful to check the merge result every time.

(Personally I'd be happier with all of this if Git had it split out into a separate "resolve" command one could invoke on each file. I think the git merge-file command is, in fact, mostly what one wants here, except that it is a pain to use. With a more useable interface, instead of -X ours and -s ours and -X theirs and so on, and various merge drivers in .gitattributes, we could just let the merge conflicts happen, inspect them, decide which side(s) to keep if that suffices, and go with that. Of course if one goes much further down this road, one ends up with a GUI merge tool...)

这篇关于通过自动合并所有更改来解决特定文件的git冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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