我正在尝试做一些我认为应该非常简单的事情,但已经变成了一个兔子洞,我认为一定有更好的方法。
想象一下,您有两个连续的补丁文件(代表连续的更改)到一个源文件,但您没有源文件本身。
如何将两个补丁组合成一个代表组合更改集的补丁。将组合补丁应用到源文件的结果应该与按顺序应用两个补丁的结果相同。应保留所有上下文
有没有一个众所周知的算法?
例子。拿这两个补丁
@@ -1,1 +1,2 @@
+ add this first line
this line is just context
Run Code Online (Sandbox Code Playgroud)
@@ -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
Run Code Online (Sandbox Code Playgroud)
结果将是:
@@ -1,1 +1,2 @@
+ change the first line
this line is just context
@@ -7,2 +7,2 @@
context
- change this line
+ …Run Code Online (Sandbox Code Playgroud)