一、实例
test@test-desktop:~/Desktop/patchtest$ cat /home/test/Desktop/patch.txt
diff -Nur patchtest/san1/test/hello.txt patchtest/san2/test/hello.txt
--- patchtest /san1 /test/hello.txt 2009-11-28 22:24:59.000000000 +0800
+++ patchtest/san2/test/hello.txt 2009-11-28 22:25:03.000000000 +0800
@@ -1 +1 @@
-hello
+hi
test@test-desktop:~/Desktop/patchtest$ patch -p1 < /home/test/Desktop/patch.txt
patching file san1/test/hello.txt
test@test-desktop:~/Desktop/patchtest$ cat san1/test/hello.txt
hi
如果需要撤销补丁,可以执行 patch -p1 -R < /home/test/Desktop/patch.txt
二、说明
1、关于p0和p1
使用-p0是从当前文件夹寻找一个patchtest文件夹,然后再找san1文件夹,依次类推;
使用-p1是截断第一层目录,从当前路径找san1文件夹。。。
2、patch -p1是针对旧的文件打新的补丁。
三、参考资料
- 生成补丁:
diff -Nur program-1.0 program-2.0 > program-2.0.patch
- 打上补丁:
cat program-2.0.patch | patch -p0
- 撤销 补丁:
cat program-2.0.patch | patch -p0 -R
-w 忽略所有空格和制表符,将所有其他空白字符串视为一致。例如,if ( a == b ) 与 if(a==b) 相等