使用和制作patch文件

发表时间: 2007-2-13 20:57    作者: superuser    来源: 迷茫人

字体: | 打印

原文http://www.linuxsir.org/bbs/showthread.php?t=240802

今天上QQ的时候发现eva不能用了,后来又看到了解决方法,所以想打个补丁,只是不会:-)。后来查了查明确了,写了个总结,分享一下,也不知道曾经有没有这方面的东西,希望我这个不是多余的。

创建补丁文件:

CODE:

diff -Naur 旧的文件夹 新的文件夹 > patch文件
或者
diff -Naur 旧的文件 新的文件 > patch文件

对于文件夹层数的一些限制

在创建patch的时候文件夹的层数应当是一样的,比方

CODE:

--- old/modules/pcitableMon Sep 27 11:03:56 1999
+++ new/modules/pcitableTue Dec 19 20:05:41 2000

这样是能够的。

CODE:

--- old/try1/other/modules/pcitableMon Sep 27 11:03:56 1999
+++ new/modules/pcitableTue Dec 19 20:05:41 2000

这样做可能会有一些问题。

怎样使用patch
对于一个patch文件,有两种经常使用用法:
1.

CODE:

cat new-patch | patch -p02.

2、

CODE:

patch -p0 < new-patch

patch命令里面的层数(-p0?-p1?)
參数-p来指定从第几层開始比較。比方有一个patch文件的补丁头是这种:

CODE:

--- old/modules/pcitableMon Sep 27 11:03:56 1999
+++ new/modules/pcitableTue Dec 19 20:05:41 2000

假设使用參数-p0,就表示从当前文件夹,找一个叫作new的文件夹,在它以下找一个叫modules的文件夹,再在它以下找一个叫pcitableMon的文件夹。
假设使用參数-p1,就表示忽略第一层,从当前文件夹找一个叫modules的文件夹,在它以下找一个叫modules的文件夹。这样会忽略掉补丁头提到的new文件夹。
依此类推。

patch文件的结构
补丁头
补丁头是分别由---/+++开头的两行,用来表示要打补丁的文件。
一个补丁文件里的多个补丁
一个补丁文件里可能包括以---/+++开头的非常多节,每一节用来打一个补丁。所以在一个补丁文件里能够包括好多个补丁。

块是补丁中要改动的地方。它通常由一部分不用改动的东西開始和结束。他们仅仅是用来表示要改动的位置。他们通常以@@開始,结束于还有一个块的開始或者一个新的补丁头。
块的缩进
块会缩进一列,而这一列是用来表示这一行是要添加�还是要删除的。
块的第一列
+号表示这一行是要加上的。
-号表示这一行是要删除的。
没有加号也没有减号表示这里仅仅是引用的而不须要改动。

一个patch的样例

CODE:

diff -u old/modules/pcitable new/modules/pcitable
--- old/modules/pcitableMon Sep 27 11:03:56 1999
+++ new/modules/pcitableTue Dec 19 20:05:41 2000
@@ -1,4 +1,6 @@
0x0e110xae10"cpqarray""Compaq|Smart-2/P RAID Controller"
+0x10000x0010"cpqarray""Compaq|Integrated Array Controller"
+0x10110x0046"cpqarray""Compaq|Smart-2/P RAID Controller"
0x0e110xae32"tlan""Compaq|Netelligent 10/100"
0x0e110xae34"tlan""Compaq|Netelligent 10"
0x0e110xae35"tlan""Compaq|Integrated NetFlex-3/P"
@@ -21,6 +23,7 @@
0x10000x000f"ncr53c8xx""Symbios|53c875"
0x10000x0012"ncr53c8xx""Symbios|53c895a"
0x10000x008f"ncr53c8xx""Symbios|53c875J"
+0x10000x000a"sym53c8xx""Symbios|53c1510"
0x10000x0701"yellowfin""Symbios|83C885 gigabit ethernet"
0x10000x0702"yellowfin""Symbios|Yellowfin G-NIC gigabit ethernet"
0x10110x0001"tulip""DEC|DECchip 21050"
--- old/usr/share/kudzu/pcitableSun Sep 26 17:11:23 1999
+++ new/usr/share/kudzu/pcitableTue Dec 19 20:05:41 2000
@@ -15,6 +15,8 @@
0x0e110x3034"unknown""Compaq|QVision 1280/p"
0x0e110x4000"unknown""Compaq|4000 [Triflex]"
0x0e110xa0f3"ignore""Compaq|Triflex PCI to ISA Bridge"
+0x10000x0010"cpqarray""Compaq|Integrated Array Controller"
+0x10110x0046"cpqarray""Compaq|Smart-2/P RAID Controller"
0x0e110xae10"cpqarray""Compaq|Smart-2/P RAID Controller"
0x0e110xae29"unknown""Compaq|MIS-L"
0x0e110xae2a"unknown""Compaq|MPC"
@@ -46,6 +48,7 @@
0x10000x000f"ncr53c8xx""Symbios|53c875"
0x10000x0012"ncr53c8xx""Symbios|53c895a"
0x10000x008f"ncr53c8xx""Symbios|53c875J"
+0x10000x000a"sym53c8xx""Symbios|53c1510"
0x10000x0701"yellowfin""Symbios|83C885 gigabit ethernet"
0x10000x0702"yellowfin""Symbios|Yellowfin G-NIC gigabit ethernet"
0x10000x0901"unknown""Symbios|61C102"

分析
这个样例是由命令

CODE:

diff -u old/modules/pcitable new/modules/pcitable

创建的。只是最好是用命令diff -Naur来取代diff -u。
它改动了两个文件,new/modules/pcitable和new/usr/share/kudzu/pcitable。
第一个补丁头包括两个块,分别添加�了两行和一行。

这个是參考了这篇文http://www.cpqlinux.com/patch.html来总结翻译。因为刚刚接触这些东西,非常多地方可能翻译的不恰当,尤其是一些术语,如有发现问题,请给我留言说明,以便我来改正,谢谢。

我也来说两句 查看所有评论 相关评论

  • superuser (2007-2-13 21:12:26)

    Patching (very) Mini Howto
    Introduction

    This very short document is a slightly lengthened version of an email I wrote in 2003 on the subject of patches, I've put it here in case it could be useful to anyone else.
    The Howto

    cd into the directory containing the sources you want to patch:

    CODE:

    $ cd madwifiThen you need to pipe the patch file into the program 'patch', like this:

    CODE:

    $ cat /path/to/patch/patch.diff | patch -p1The processs for applying gzipped or bzipped patches is almost identical, only you use a modified version of 'cat' which can handle the compression thats been used e.g:

    CODE:

    $ bzcat /path/to/patch/patch.bz2 | patch -p1for bzips, or

    CODE:

    $ zcat /path/to/patch/patch.gz2 | patch -p1for the (more common) gzips.

    Another way which might interest some people (which I've just descovered) is to do things the other way around, in this way you can do it without running cat:

    CODE:

    $ patch -p1 < patchI'm not exactly sure how to do this with zipped patches just yet however, my experiments would lead me to belive that its more complex than most of what's above.

    The option -p1 tells the patch program to remove 1 layer of all the filenames from the input, you do this because normally the person who made the patch is one directory closer to / than you. The best way to explain this is too look at the content of a patch (this is part of the wireless extensions patch):

    CODE:

    diff -u -p linux/include/linux/wireless.15.h linux/include/linux/wireless.h
    --- linux/include/linux/wireless.15.h   Fri Jan 10 16:55:07 2003
    +++ linux/include/linux/wireless.h  Wed Apr  2 16:33:31 2003
    The lines mention "linux/include/[...]", now if you have more than one set of kernel sources on your system, then the one you want to patch will not necessarily be in as directory called 'linux', the -p1 option would strip the linux from the filename and just leave:

    CODE:

    diff -u -p include/linux/wireless.15.h include/linux/wireless.h
    --- include/linux/wireless.15.h   Fri Jan 10 16:55:07 2003
    +++ include/linux/wireless.h  Wed Apr  2 16:33:31 2003
    From the above discussion, it should be fairly easy to see that patch strips from the left hand side, and removes n slashes. Where n is the number the 'p' option.

    There are a couple of other things which I thinks its handy to know about patch, first is that not all patches will go on 'cleanly', sometimes you will get messages like 'Hunk suceeded at offset 32', this means that that part of the patch applied, but not in the exact same place as the original author intended. This happens all the time with the madwifi driver from cvs.

    Second is the -R swich for 'patch', this:

    CODE:

    $ cat /path/to/patch/patch.diff | patch -p1 -Rwould remove the patch from your current directory tree.
    And finally

    One last thing to remember: I am no expert, and some of this may be a bit wrong, missing something or whatever. Drop me a line if it is.

使用和制作patch文件的更多相关文章

  1. 搞了一下午时间全浪费在这了,其实是自己拷贝了patch文件,导致tab变成了空格的错

    很老实的基于最新的kernel,源文件,修改了代码.通过diff -uNr --show-c-function dir1 dir2 > ipv6.patch制作了patch文件,准备代码上库构建 ...

  2. quilt - 制作patch的工具

    quilt - 制作patch的工具 在尝试为openwrt做一个patch时,查到这个工具.openwrt官方已经有很详细的文档对步骤进行说明了. quilt并不是专为openwrt的开发工具.qu ...

  3. 制作自己的rpm包,并为其制作patch包。

    本文分为两个部分,第一部分是制作一个简单的自己的rpm包,并安装运行它.第二部分是为其制作一个patch包,并通过spec配置文件去打补丁,安装.运行打补丁后的程序. 一.安装工具 [yh@local ...

  4. 3种方法快速制作tpk文件 [转]

    tpk是ArcGIS10.1推出的一种新的数据文件类型,主要是用于将切片文件打包形成离线地图包,tpk可以在ArcGIS Runtime或者ArcGIS for Android/iOS中作为切片底图被 ...

  5. diff和patch的使用、patch文件的格式解说

    为了弄懂 patch中的 p0   p1    和.orig文件是啥,找到了这篇文章! 来源:http://www.cnblogs.com/super119/archive/2010/12/18/19 ...

  6. NSIS使用教程(安装包制作安装文件教程,如何封装打包文件) 中文版

    nsis中文版(Nullsoft Scriptable Install System)是一个专业的开源的可以用来封闭Windows程序的实用工具,是一个开源的 Windows 系统下安装程序制作程序. ...

  7. Ubuntu下制作ISO文件

    利用Ubuntu自带的命令mkisofs就可以制作iso文件,具体方法如下: 1.   如果你是直接从cd压制iso文件的,执行 sudo umount /dev/cdromdd if=/dev/cd ...

  8. 如何制作CSR文件?

    如何制作CSR文件? 在申请数字证书之前,您必须先生成证书私钥和证书请求文件(CSR,Cerificate Signing Request),CSR是您的公钥证书原始文件,包含了您的服务器信息和您的单 ...

  9. 用C#制作PDF文件全攻略

    用C#制作PDF文件全攻略 目  录 前    言... 3 第一部分 iText的简单应用... 4 第一章 创建一个Document 4 第一步 创建一个Document实例:... 5 第二步 ...

随机推荐

  1. Windows Services的1053错误的解决办法之一:修改注册表允许的响应时间

    Error: 'The service did not respond in a timely fashion' (ServicesPipeTimeout) when attempting when ...

  2. java class生成jar包(转)

    进入dos操作符窗口cd进入要打成jar包的class文件所有文件夹目录jar cvf [生成jar的名称.jar] [列出class文件] //若有多个,以空隔隔开 如:一.操作零散的单个或几个cl ...

  3. 手动加入PE文件数字签名信息及格式具体解释图之下(历史代码,贴出学习)

    #include <windows.h> HANDLE hWriteFileHandle = NULL ; HANDLE hReadFileHandle = NULL ; HANDLE h ...

  4. java绘图板

    JAVA绘图板 import java.awt.BasicStroke; import java.awt.BorderLayout; import java.awt.Button; import ja ...

  5. Hadoop基于文件的数据结构及实例

    基于文件的数据结构 两种文件格式: 1.SequenceFile 2.MapFile SequenceFile 1.SequenceFile文件是Hadoop用来存储二进制形式的<key,val ...

  6. C++学习之路—继承与派生(三):多重继承与虚基类

    (根据<C++程序设计>(谭浩强)整理,整理者:华科小涛,@http://www.cnblogs.com/hust-ghtao转载请注明) 多重继承是指一个派生类有两个或多个基类.例如,有 ...

  7. DLP底座(威创定制)

    品牌:威创 型号:BC06730-1000 生产商:广东威创视讯科技股份有限公司 1.DLP底座说明 DLP底座由威创统一定制,确保了整套系统的完整性和可靠性.材质为钢结构,根据淄川地下管线中心的现场 ...

  8. [置顶] 手把手教你iOS消息推送证书生成以及Push消息

    iOS推送消息是许多iOS应用都具备的功能,今天在给应用加推送功能,在生成证书的过程中,发生了各种令人蛋痛的事.下面就把步骤拿出来分享下: iOS消息推送的工作机制可以简单的用下图来概括: Provi ...

  9. 让delphi程序不受WINDOWS日期格式的影响(使用SetLocaleInfo函数和Application.UpdateFormatSettings)

    如果WINDOWS系统的短日期格式为“yyyy/m/d”,执行下面的代码会报错:2013-01-29 00:00:00不是合法的日期procedure TFrmQuerySale.FormShow(S ...

  10. typedef和define具体的具体差别

      1) #define是预处理指令,在编译预处理时进行简单的替换,不作正确性检查,不关含义是否正确照样带入,仅仅有在编译已被展开的源程序时才会发现可能的错误并报错.比如: #define PI 3. ...