linux diff patch的应用

 对diff,patch的用法总是一知半解

在这里做个标记

diff [options] oldfile newfile
[options]
-r:递归选项,包含子目录文件
-u:以统一格式创建补丁文件,标准格式
-N:正确处理新创建或已删除文件的情况

cd ../old_dir
diff -urN old_dir new_dir >patchfile
例如:
$ cd ~/work
$ ls
  olduboot test temp
$ ls test

   newuboot
$ diff -urN olduboot test/newuboot >ubootpatch
注:diff时,应该是在olduboot的同级目录下进行。


patch [options] [originalfile] [patchfile]
[options]
-p0:从当前目录查找目标文件(夹)
-p1:忽略第一次目录,从当前目录开始查找
-E:若发现空文件,则删除
-R:在补丁文件中的“新”文件和“旧”文件调换过来。

例如:ubootpatch格式如下:
$ pwd
  ~/work #当前目录
$ head -3 ubootpatch
diff -urN olduboot/arch/arm/cpu/arm926ejs/sc8800g/check_reboot.c test/newuboot/arch/arm/cpu/arm926ejs/sc8800g/check_reboot.c
--- olduboot/arch/arm/cpu/arm926ejs/sc8800g/check_reboot.c      2011-09-27 14:55:50.000000000 +0800
+++ test/newuboot/arch/arm/cpu/arm926ejs/sc8800g/check_reboot.c 2011-09-27 14:25:25.000000000 +0800

-p0:表示从当前目录~/work下查找一个叫做olduboot的文件夹
-p1:表示忽略掉第一层目录(olduboot),从当前目录~/work下查找arch文件夹,继而遍历查找到check_reboot.c文件
在这里如果要用参数p1,则需要先进入olduboot文件夹中,再运行:patch -p1 < ubootpatch

##然后在需要应用patch的地方使用下述命令即可:
$ patch -p0 < ubootpatch
or
$ cd olduboot
$ patch -p1 < ../ubootpatch

如果你需要打补丁的文件夹olduboot在其他目录,如:~/temp/olduboot
则需要如下操作:
$ cd ~/work/ubootpatch ~/temp/
$ cd ~/temp
$ ls
  olduboot
$ patch -p0 <ubootpatch
or
$ cd olduboot
$ patch -p1 <../ubootpatch

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值