/***************************************************************************** * Linux diff p Atch * Statement: * Often need to patch the code, but found that they do not patch, often look at the patch to change the code, efficiency * that is a low ah, will not learn Bai, anyway patch has-r fallback, not afraid of error. * 2015-12-28 Shenzhen Nanshan Ping Shan village Zengjianfeng ********************************************************* *******************/ \\\\\\-*-Directory-*-//////|Reference article:|One, cat main1.c|second, cat main2.c|c. Execute diff:|iv. Execute Patch:|v. Patch back:-----------------------Reference article:1. Use diff and patch tools to maintain source http://www.ibm.com/developerworks/cn/linux/l-diffp/index.html 2. diff and Patch Usage guide http://www.cnblogs.com/cute/archive/2011/04/29/2033011.htmlone, cat main1.c #include<stdio.h>intMainintargcChar**argv) {printf ("ZENGJF test for diff and Patch.\n" ); } II, cat main2.c #include<stdio.h>intMainintargcChar**argv) {printf ("ZENGJF test for diff and Patch.\n" ); } III, execute diff:1. $: Diff-nur main1.c main2.c >Main.patch2The . main.patch file is generated under the current directory:---main1.c -- A- - -: $:49.388152208+0800+ + main2.c -- A- - -: -:17.376180914+0800 @@ -2,5+2,8 @@ intMainintargcChar**argv) { + + +printf ("ZENGJF test for diff and Patch.\n" ); } Four, execute Patch:1The current directory is: main1.c main2.c main.patch2. Cat main1.c #include<stdio.h>intMainintargcChar**argv) {printf ("ZENGJF test for diff and Patch.\n" ); } 3. $: patch-p0 < Main.patch <right>Patching file main1.c4. Cat main1.c #include<stdio.h>intMainintargcChar**argv) {printf ("ZENGJF test for diff and Patch.\n" ); } 5. $: Patch P0 < Main.patch <error>Patching file P0 Hunk #1FAILED at2. 1 outof hunk FAILED--saving rejects to file P0.rej6. $: Patch-p1 < Main.patch <error>can't find file to patch on input line 3Perhaps you used the wrong-p or--strip option?The text leading up to Thiswas :----------------------------------|---main1.c -- A- - -: $:49.388152208+0800|---main2.c -- A- - -: -:17.376180914+0800----------------------------------File to Patch:<cursor>7. $: patch-p0 main.patch <error> ^C v. Patch back:1The current directory is: main1.c main2.c main.patch2. Cat main1.c #include<stdio.h>intMainintargcChar**argv) {printf ("ZENGJF test for diff and Patch.\n" ); } 3. $: Patch-p0-r <main.patch Patching file main1.c4. Cat main1.c #include<stdio.h>intMainintargcChar**argv) {printf ("ZENGJF test for diff and Patch.\n" ); }
Linux diff patch