/***************************************************************************** * Linux diff patch * 声明: * 经常需要给代码打补丁,但是发现自己不会打补丁,经常看着补丁改代码,效率 * 那是一个低啊,不会就学学呗,反正patch有-R回退,不怕出错。 * * 2015-12-28 深圳 南山平山村 曾剑锋 ****************************************************************************/ \\\\\\-*- 目录 -*-////// | 参考文章: | 一、cat main1.c | 二、cat main2.c | 三、execute diff: | 四、execute patch: | 五、patch back: ----------------------- 参考文章: 1. 用Diff和Patch工具维护源码 http://www.ibm.com/developerworks/cn/linux/l-diffp/index.html 2. diff和patch使用指南 http://www.cnblogs.com/cute/archive/2011/04/29/2033011.html 一、cat main1.c #include <stdio.h> int main( int argc, char **argv ) { printf( " zengjf test for diff and patch.\n" ); } 二、cat main2.c #include <stdio.h> int main( int argc, char **argv ) { printf( " zengjf test for diff and patch.\n" ); } 三、execute diff: 1. $: diff -Nur main1.c main2.c > main.patch 2. 在当前目录下生成了main.patch文件: --- main1.c 2015-12-28 20:36:49.388152208 +0800 +++ main2.c 2015-12-28 20:25:17.376180914 +0800 @@ -2,5 +2,8 @@ int main( int argc, char **argv ) { + + + printf( " zengjf test for diff and patch.\n" ); } 四、execute patch: 1. 当前目录下有:main1.c main2.c main.patch 2. cat main1.c #include <stdio.h> int main( int argc, char **argv ) { printf( " zengjf test for diff and patch.\n" ); } 3. $: patch -p0 < main.patch <right> patching file main1.c 4. cat main1.c #include <stdio.h> int main( int argc, char **argv ) { printf( " zengjf test for diff and patch.\n" ); } 5. $: patch p0 < main.patch <error> patching file p0 Hunk #1 FAILED at 2. 1 out of hunk FAILED -- saving rejects to file p0.rej 6. $: patch -p1 < main.patch <error> can‘t find file to patch at input line 3 Perhaps you used the wrong -p or --strip option? The text leading up to this was: ---------------------------------- |--- main1.c 2015-12-28 20:36:49.388152208 +0800 |--- main2.c 2015-12-28 20:25:17.376180914 +0800 ---------------------------------- File to patch: <cursor> 7. $: patch -p0 main.patch <error> ^C 五、patch back: 1. 当前目录下有:main1.c main2.c main.patch 2. cat main1.c #include <stdio.h> int main( int argc, char **argv ) { printf( " zengjf test for diff and patch.\n" ); } 3. $: patch -p0 -R < main.patch patching file main1.c 4. cat main1.c #include <stdio.h> int main( int argc, char **argv ) { printf( " zengjf test for diff and patch.\n" ); }
时间: 2024-10-10 21:36:19