可以让git主要自动合并XML命令不敏感的文件? [英] Can git be made to mostly auto-merge XML order-insensitive files?

查看:276
本文介绍了可以让git主要自动合并XML命令不敏感的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在合并Lightswitch分支时,通常同事会向我也修改过的实体添加属性,这会导致合并冲突,因为新的XML条目将添加到lsml文件中的相同位置。



我可以有效地总是通过接受左右顺序来解决这些问题,因此顺序不重要,因为顺序在这些特定情况下并不重要。在罕见的情况下,这是无效的,这会在项目中产生一个错误,我接受这是一个风险(但没有遇到过)。



有一种方法(最好是文件扩展名)让git自动接受源位置和目标位置的变化,并简单地将一个位置放在另一个位置下面?

解决方案

这通常很难。



一些试图使用Git的union merge (现在比早期更容易访问;就像在那个问题中一样,你只需在中添加 merge = union .gitattributes 文件),但这通常不起作用。它可能有时会工作。如果您的XML始终是结构化的,以便天真的面向行的联合合并生成有效的XML(基本上,将整个XML子元素全部保留在一行中),那么它可以很好地工作 并且总是添加全新的XML子元素。



在Git中,可以编写自定义合并驱动程序。为XML编写一个有用的代码很困难。

首先,我们需要一个XML diff引擎,比如 SylvainThénault的xmldiff ,为三个XML文件(合并基础,本地或<$ c $)构造两个字符串到字符串(或树到树)编辑c> - 我们的和其他或 - 他们的文件:diff base -vs-local和base-vs-ours)。这个特殊的看起来像Python的 difflib 。 (但是,由于引用的论文,它看起来像是产生了树移动/嵌套级操作以及简单的插入和删除操作,这对于树到树编辑算法来说是自然而合理的事情,并且可能)

然后,给出两个这样的差异,我们需要代码来合并它们。 union 方法是忽略所有删除操作:只需将所有添加项添加到基本版本(或等同地将其他添加到本地或本地添加到其他)。我们还可以将树插入/删除操作与真实(非联合式)合并相结合,甚至可能会声明冲突。 (可能会很好,允许不同的树嵌套级别更改处理,由DTD等模糊东西驱动。)



到目前为止,最后这些部分不是正如我所知道的,在任何地方完成。除此之外,这里链接的Python xmldiff是一个相当大的代码块(我没有仔细阅读过它,也没有尝试安装它,我只是下载并剔除了它,它实现了Myers类算法和来自斯坦福大学论文)。


When merging Lightswitch branches, often colleagues will add properties to an entity I also modified, which will result in a merge conflict, as the new XML entries are added to the same positions in the lsml file.

I can effectively always solve these by accepting left and right in no particular order, so one goes above the other, as order isn't important in these particular instances. On the rare instances this isn't valid, this would produce an error in the project anyway, which I accept as a risk (but haven't encountered).

Is there a way (preferably for the file extension) to get git to automatically accept source and target changes for the same position and simply place one beneath the other?

解决方案

This gets pretty hard in general.

Some have attempted to use Git's union merge (which is more accessible now than it was in early days; as in that question, you just add merge=union in a .gitattributes file), but this does not work in general. It might work sometimes. Boiling it down a lot, it works if your XML is always structured so that naive line-oriented union merge produces valid XML (basically, keeping whole XML sub-elements all on one line), and you are always adding whole new XML sub-elements.

It is possible, in Git, to write a custom merge driver. Writing a useful one for XML is hard.

First we need an XML diff engine, such as Sylvain Thénault's xmldiff, to construct two string-to-string (or tree-to-tree) edits for three XML files (the merge base, local or --ours, and other or --theirs files: diff base-vs-local and base-vs-ours). This particular one looks like it works similarly to Python's difflib. (However, due to the referenced papers, it looks like it produces tree move / nesting-level operations as well as simple insert and delete. This is a natural and reasonable thing for a tree-to-tree edit algorithm to do, and probably actually desirable here.)

Then, given two such diffs, we need code to combine them. The union method is to ignore all deletions: simply add all additions to the base version (or, equivalently, add the "other" additions to the "local", or the "local" additions to the "other"). We could also combine tree insert/delete operations a la "real" (non-union-style) merges, and perhaps even declare conflicts. (And it might be nice to allow different handling of tree nesting-level-changes, driven by something vaguely like a DTD.)

These last parts are not, as far as I know anyway, done anywhere. Besides that, the Python xmldiff I linked here is a fairly big chunk of code (I have not read it anywhere near closely, nor attempted to install it, I just downloaded it and skimmed—it implements both a Myers-like algorithm, and the fancier "fast match / edit script" algorithm from the Stanford paper).

这篇关于可以让git主要自动合并XML命令不敏感的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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