免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1280 | 回复: 0
打印 上一主题 下一主题

linux中diff和patch使用操作(二) ---转载 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-07-02 16:17 |只看该作者 |倒序浏览
二、为多个文件进行补丁操作
1、创建测试文件夹
[armlinux@lqm patch]$ mkdir prj0
[armlinux@lqm patch]$ cp test0 prj0
[armlinux@lqm patch]$ ls
prj0  test0  test1  test1.patch
[armlinux@lqm patch]$ cd prj0/
[armlinux@lqm prj0]$ ls
test0
[armlinux@lqm prj0]$ cat >>prj0name
> --------
> prj0/prj0name
> --------
> EOF
[armlinux@lqm prj0]$ ls
prj0name  test0
[armlinux@lqm prj0]$ cat prj0name
--------
prj0/prj0name
--------
[armlinux@lqm prj0]$ cd ..
[armlinux@lqm patch]$ mkdir prj1
[armlinux@lqm patch]$ cp test1 prj1
[armlinux@lqm patch]$ cd prj1
[armlinux@lqm prj1]$ cat >>prj1name
> ---------
> prj1/prj1name
> ---------
> EOF
[armlinux@lqm prj1]$ cat prj1name
---------
prj1/prj1name
---------
[armlinux@lqm prj1]$ cd ..
2、创建补丁
[armlinux@lqm patch]$ diff -uNr prj0 prj1 > prj1.patch
[armlinux@lqm patch]$ more prj1.patch
diff -uNr prj0/prj0name prj1/prj0name
--- prj0/prj0name       2006-08-18 09:25:11.000000000 +0800
+++ prj1/prj0name       1970-01-01 08:00:00.000000000 +0800
@@ -1,3 +0,0 @@
---------
-prj0/prj0name
---------
diff -uNr prj0/prj1name prj1/prj1name
--- prj0/prj1name       1970-01-01 08:00:00.000000000 +0800
+++ prj1/prj1name       2006-08-18 09:26:36.000000000 +0800
@@ -0,0 +1,3 @@
+---------
+prj1/prj1name
+---------
diff -uNr prj0/test0 prj1/test0
--- prj0/test0  2006-08-18 09:23:53.000000000 +0800
+++ prj1/test0  1970-01-01 08:00:00.000000000 +0800
@@ -1,3 +0,0 @@
-111111
-111111
-111111
diff -uNr prj0/test1 prj1/test1
--- prj0/test1  1970-01-01 08:00:00.000000000 +0800
+++ prj1/test1  2006-08-18 09:26:00.000000000 +0800
@@ -0,0 +1,4 @@
+222222
+111111
+222222
+111111
[armlinux@lqm patch]$ ls
prj0  prj1  prj1.patch  test0  test1  test1.patch
[armlinux@lqm patch]$ cp prj1.patch ./prj0
[armlinux@lqm patch]$ cd prj0
[armlinux@lqm prj0]$ patch -p1
patching file prj0name
patching file prj1name
patching file test0
patching file test1
[armlinux@lqm prj0]$ ls
prj1name  prj1.patch  test1
[armlinux@lqm prj0]$ patch -R -p1
patching file prj0name
patching file prj1name
patching file test0
patching file test1
[armlinux@lqm prj0]$ ls
prj0name  prj1.patch  test0
-------------------
总结一下:
单个文件
diff –uN  from-file  to-file  >to-file.patch
patch –p0
patch –RE –p0
多个文件
diff –uNr  from-docu  to-docu  >to-docu.patch
patch –p1
patch –R –p1
-------------------
三、应用
为内核打补丁。前面在创建交叉编译工具链时,其中有一步就是为内核打补丁。当时还不是特别了解,现在很清晰了。参考前面的文章《基于ARM+Linux嵌入式开发的开发工具链的建立》。
1、首先是解压,因为发布的补丁文件都是使用gzip压缩的。
$gunzip ../setup-dir/ patch-2.4.21-rmk1.gz
2、然后进入你的内核源代码目录
$cd linux-2.4.21
3、打补丁
$patch –p1
打完补丁后,需要检查一下有没有拒绝执行的文件,即检查.rej文件的存在。使用命令:
$find  .  -name  *.rej
如果发现,会将其输出到标准输出终端,默认屏幕。当然,你也可以采用重定向,输出到指定文件,比如reject。
$fine  .  -name  *.rej  >reject
然后可以查看reject的内容了。(T002)
              
              
              
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/35795/showart_1071416.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP