我需要一些函数'apply_patch':
result_string = apply_patch('origin_file.txt', 'origin_file.txt.patch')
或一些命令(对于Windows和Linux):
if linux:
result_string = os.system('linux_patch --apply origin_file.txt origin_file.txt.patch')
elif windows:
result_string = os.system('windows_patch --apply origin_file.txt origin_file.txt.patch')
有用的信息:我使用mercurial作为版本控制系统
答案 0 :(得分:1)
检查实用程序patch。它做你期望的。假设您位于项目的根目录中,您可以尝试:
$ patch --dry-run < file.diff
- dry-run 会告诉您补丁是否适用,而不是真正应用它。最终你必须使用选项 -p n 来让补丁知道从路径中删除目录(查看diff文件的标题)。
如果已经应用了补丁,该实用程序将询问您是否要撤消补丁。
使用mercurial,您也可以尝试' hg import '。如果您的程序需要它,那么您可以从mercurial导入相应的模块。