Linux diff patch

/*****************************************************************************
* Linux diff patch
* 声明:
* 经常需要给代码打补丁,但是发现自己不会打补丁,经常看着补丁改代码,效率
* 那是一个低啊,不会就学学呗,反正patch有-R回退,不怕出错。
*
* 2015-12-28 深圳 南山平山村 曾剑锋
****************************************************************************/ \\\\\\-*- 目录 -*-//////
| 参考文章:
| 一、cat main1.c
| 二、cat main2.c
| 三、execute diff:
| 四、execute patch:
| 五、patch back:
----------------------- 参考文章:
. 用Diff和Patch工具维护源码
http://www.ibm.com/developerworks/cn/linux/l-diffp/index.html
. diff和patch使用指南
http://www.cnblogs.com/cute/archive/2011/04/29/2033011.html
. 补丁格式 diff patch
http://blog.sina.com.cn/s/blog_51cea4040101atql.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:
. $: diff -Nur main1.c main2.c > main.patch
. 在当前目录下生成了main.patch文件:
--- main1.c -- ::49.388152208 +
+++ main2.c -- ::17.376180914 +
@@ -, +, @@ int main( int argc, char **argv )
{
+
+
+
printf( " zengjf test for diff and patch.\n" );
} 四、execute patch:
. 当前目录下有:main1.c main2.c main.patch
. cat main1.c
#include <stdio.h> int main( int argc, char **argv )
{
printf( " zengjf test for diff and patch.\n" );
}
. $: patch -p0 < main.patch <right>
patching file main1.c
. cat main1.c
#include <stdio.h> int main( int argc, char **argv )
{ printf( " zengjf test for diff and patch.\n" );
}
. $: patch p0 < main.patch <error>
patching file p0
Hunk # FAILED at .
out of hunk FAILED -- saving rejects to file p0.rej
. $: 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 -- ::49.388152208 +
|--- main2.c -- ::17.376180914 +
----------------------------------
File to patch: <cursor>
. $: patch -p0 main.patch <error>
^C 五、patch back:
. 当前目录下有:main1.c main2.c main.patch
. cat main1.c
#include <stdio.h> int main( int argc, char **argv )
{ printf( " zengjf test for diff and patch.\n" );
}
. $: patch -p0 -R < main.patch
patching file main1.c
. cat main1.c
#include <stdio.h> int main( int argc, char **argv )
{
printf( " zengjf test for diff and patch.\n" );
} 六、实例分析:
. patch 部分内容:
diff --git a/proguard.flags b/proguard.flags
index 6d41d17..ffbc39a
--- a/proguard.flags
+++ b/proguard.flags
@@ -, +, @@
-keep class com.android.settings.MasterClearConfirm
-keep class com.android.settings.accounts.*
-keep class com.android.settings.fuelgauge.*
-
+-keep class com.android.settings.ethernet.*
. 解析:@@ -, +, @@
. @@ -表示代表a/proguard.flags文件;
. 11代表下面显示的代码是从a/proguard.flags文件的第11行开始;
. 4代表a/proguard.flags被操作了;
. +代表b/proguard.flags文件
. 11代表下面显示的代码是从b/proguard.flags文件的第11行开始;
. 4代表b/proguard.flags被操作了;
. @@ 代表结束
上一篇:GPU CUDA常量内存使用


下一篇:关于git的打patch的功能