可以使用与 GNU 补丁兼容的 python 模块 difflib 创建补丁吗?我尝试使用 Unified_diff 和 context_diff,还尝试将 lineterm 指定为“\n”,但我仍然收到此错误:
[intense@Singularity Desktop]$ patch diff.patch test.txt
patch unexpectedly ends in middle of line
patch: **** Only garbage was found in the patch input.
我使用 file.writelines(diff) 将补丁写入文件(一段代码http://pastebin.com/3HAWfwVf)
文件 test.txt:
Hello, this is test
blah
文件 test2.txt:
Hello, this is test
blah, dfsgjdfgj
lfkdjgkldfjgkldfjgkl
并生成补丁:
--- /home/intense/Desktop/test.txt
+++ /home/intense/Desktop/test2.txt
@@ -1,2 +1,7 @@
-Hello, this is test
-blah+Hello,+this+is+test+blah,+dfsgjdfgj+lfkdjgkldfjgkldfjgkl
谢谢你的帮助。