2

类似于 git 如何合并两个分支,但是:

  • 使用蟒蛇
  • text1而不是我们拥有的两个分支text2
  • 而不是我们有的共同提交text0- text1 和 text2 的先前版本

diff-match-patch可能可以用来完成这个任务,但是我在 doc 和 python 包源代码中都没有找到合适的方法(因为文档不完整)。

到目前为止,我想出了这个:

c = "some base text with meaning"
a = "changed base text with meaning"
b = "some base text without meaning"
p1 = dmp.patch_make(c, a)
p2 = dmp.patch_make(c, b)
dmp.patch_apply(p1 + p2, c)
> ('changed base text without meaning', [True, True])

看起来它有效,但我不确定这是否是正确的方法。有 diff-match-patch 经验的人可以批准这个吗?

4

0 回答 0