将两个补丁组合成一个补丁的算法?

问题描述 投票:0回答:1

我正在尝试做一些我 认为 应该非常简单但已经变成了一个相当困难的事情,我认为必须有更好的方法。

假设您有两个连续的源文件补丁文件(代表顺序更改),但您没有源文件本身。

您如何将两个补丁组合成一个补丁,代表组合的更改集。将组合补丁应用到源文件的结果应该与按顺序应用两个补丁相同。应保留所有上下文

是否有一个众所周知的算法?

例子。拿下这两个补丁

@@ -1,1 +1,2 @@
+ add this first line
this line is just context
@@ -1,2 +1,2 @@
- add this first line
+ change the first line
this line is just context
@@ -7,2 +7,2 @@
context
- change this line
+ to this one
more context

结果会是:

@@ -1,1 +1,2 @@
+ change the first line
this line is just context
@@ -7,2 +7,2 @@
context
- change this line
+ to this one
more context

我为这个用例找到的唯一工具/库是这个,但在测试中它有很多错误而且代码太密集以至于我无法理清底层算法是什么: https://github.com/twaugh/patchutils

git diff patch
1个回答
0
投票

这个答案(由这个其他答案引用)指向

combinediff
中的一个
patchutils
实用程序。

您可以找到作为 debian 软件包分发的 patchutils:https://packages.debian.org/search?keywords=patchutils

手册页:https://linux.die.net/man/1/combinediff

© www.soinside.com 2019 - 2024. All rights reserved.