diff

Linux diff创建补丁以及patch打补丁

淺唱寂寞╮ 提交于 2020-11-17 11:09:33
首先介绍一下diff和patch。在这里不会把man在线文档上所有的选项都介绍一下,那样也没有必要。在99%的时间里,我们只会用到几个选项。所以必须学会这几个选项。 1、diff -------------------- NAME diff - find differences between two files SYNOPSIS diff [options] from-file to-file -------------------- 简单的说,diff的功能就是用来比较两个文件的不同,然后记录下来,也就是所谓的diff补丁。 语法格式: diff 【选项】 源文件(夹) 目的文件(夹) 就是要给源文件(夹)打个补丁,使之变成目的文件(夹),术语也就是“升级”。下面介绍三个最为常用选项: -r 是一个递归选项,设置了这个选项,diff会将两个不同版本源代码目录中的所有对应文件全部都进行一次比较,包括子目录文件。 -N 选项确保补丁文件将正确地处理已经创建或删除文件的情况。 -u 选项以统一格式创建补丁文件,这种格式比缺省格式更紧凑些。 常用命令,在某文件夹下,对比两个文件(夹): diff -urN [old_directory] [new_directory] 2、patch ------------------ NAME patch - apply a diff file

match changes by words, not by characters

亡梦爱人 提交于 2020-08-25 08:14:32
问题 I'm using difflib 's SequenceMatcher to get_opcodes() and than highlight the changes with css to create some kind of web diff . First, I set a min_delta so that I consider two strings different if only 3 or more characters in the whole string differ, one after another ( delta means a real, encountered delta, which sums up all one-character changes): matcher = SequenceMatcher(source_str, diff_str) min_delta = 3 delta = 0 for tag, i1, i2, j1, j2 in matcher.get_opcodes(): if tag == "equal":