1 概述
补丁主要用于更新代码时不用重新下载源码,只下载补丁,然后再原代码上将这些补丁打上就得到了更新后的代码。
2 生成补丁
windows 下对比文件:
生成补丁文件mypatch
:
// u: Unified模式;p: 显示代码所在 c 函数信息;r: 递归对比下面的子目录;N: 如果文件缺少,就当做空文件来对比
/mnt/hgft/Linux/patch$ diff -uprN original/ modify/ > mypatch
/mnt/hgft/Linux/patch$ ls
modify mypatch original
/mnt/hgft/Linux/patch$ cat mypatch
diff -uprN original/file modify/file
--- original/file 1970-01-01 08:00:00.000000000 +0800
+++ modify/file 2018-12-18 21:49:31.278448300 +0800
@@ -0,0 +1,10 @@
+A=160
+B=75
+D=80
+E=105
+F1=73
+F2=146
+G=72
+H=70
+K=70
+J=80
\ No newline at end of file
diff -uprN original/first/first.c modify/first/first.c
--- original/first/first.c 2018-12-18 21:47:42.075202200 +0800
+++ modify/first/first.c 2018-12-18 21:50:43.558582500 +0800
@@ -2,5 +2,5 @@
int first(void)
{
- printf("it is the first function\n");
+ printf("itrst function\n");
}
\ No newline at end of file
diff -uprN original/first/readme modify/first/readme
--- original/first/readme 2018-12-18 21:48:50.850135900 +0800
+++ modify/first/readme 1970-01-01 08:00:00.000000000 +0800
@@ -1,8 +0,0 @@
-it is the file name.
-use to test patch
-source
-diff
-patch
-rtyu
-tuya
-yunem
diff -uprN original/main.c modify/main.c
--- original/main.c 2018-12-18 21:46:35.541396700 +0800
+++ modify/main.c 2018-12-18 21:49:59.380055600 +0800
@@ -2,5 +2,5 @@
int main(int argc, char **argv)
{
- printf("it is the main\n");
+ printf("it is thain\n");
}
\ No newline at end of file
diff -uprN original/readme modify/readme
--- original/readme 2018-12-18 21:49:31.278448300 +0800
+++ modify/readme 2018-12-18 21:50:26.148586700 +0800
@@ -2,9 +2,7 @@ A=160
B=75
D=80
E=105
-F1=73
-F2=146
-G=72
+
H=70
K=70
J=80
\ No newline at end of file
3 打补丁
/mnt/hgft/Linux/patch$ cd original
/mnt/hgft/Linux/patch/original$ patch -p1 < ../mypatch // -p1:表示忽略第1级目录
patching file file
patching file first/first.c
patching file first/readme
patching file main.c
patching file readme
打补丁之后文件对比: