文件patch
准备两个文件t1 t2
1 | echo -e "1\n2" > t1 |
通过diff命令生成patch文件
1 | diff -u t1 t2 > file.patch |
通过patch命令应用patch
1 | patch < file.patch |
or
1 | patch t1 file.patch |
or (保留原文件)
1 | patch -b < file.patch |
or (仅做检查,不实际应用)
1 | patch --dry-run < file.patch |
基于patch文件还原,也就是撤销补丁
1 | patch -R -i file.patch |
如果仅是想查看差异,建议vimdiff t1 t2
更直接
目录patch
通过diff命令生成patch
1 | diff -aurN d1 d2 > dir.patch |
通过patch命令应用patch
1 | patch -p0 < dir.patch |
撤销patch
1 | patch -R -p0 < dir.patch |
-pnum 代表从哪一级应用patch文件; 例如patch文件中的/u/src/blurfl.c, -p0 就是完全匹配, -p1 u/src/blurfl.c, p2 src/blurfl.c
一般官方提供的patch文件,进入到待更新程序的根目录后执行patch -p1 < patch_file
即可