Linux -- 文件对比,补丁文件
一、打补丁最需要注意有以下两点:
================================================================================1、要打补丁的文件必须是未做任何修改的(这个可以打开补丁文件看一下删除的文件的日期是否和我们要打补丁的文件一样就可以了)。我之前就是因为修改了厂商给的源码所以打补丁的时间打不进去,会出错,后来找资料才明白不能改打补丁前的文件。
2、还有一个就是有的补丁要一个一个的打,那是补丁做成这样的,一般厂商给说明是否需要一个一个的打,还直接打最后一个版本的就OK了,但我认为一个一个的打的补丁要严谨些,因为它的每一个补丁表示了一次功能性的修改,这样每次都可以验证补丁的正确性了。
=======================================================================
二、生成补丁(针对于发布补丁文件的人)
命令:diff -Naur 路径1/file_old文件 路径2/file_new文件 > xxx.patch文件
注:xxx.patch文件就是新旧文件生成的补丁文件,路径2最好是修改文件的当前路径这样打补丁的时候就把补丁文件放到要打补丁文件所在目录下一起打,file_new文件最好保存下来以便打补丁者打不上或者打错的时间对比下那里没有打上。
===============================================================================
三、打补丁(针对于打补丁的人)
命令:patch -bp1 < xxx.patch
注:把xxx.patch和要打补丁的文件放到一起到要打补丁文件 目录下执行上述命令会把补丁打进去更新现有文件,由于加入了参数-b所以还有生成一个.org后缀的文件它是打补丁前的源文件,确定打好了可以删除之。
=======================================================================================
四、撤销打的补丁(针对打补丁的人)
命令:patch -Rp1 < xxx.patch
注意:执行它也是在打完xxx.patch的补丁的文件的基础上执行。
===============================================================================
应用举例:
diff 对比2个文件的差异,一行一行的比较,然后显示到屏幕上 [root@teacher-feng diff]# diff hujie.txt hujie-2024.txt 旧文件 新的文件 2,3c2 < hulaoban < network --- > hulaoban --->ceo 5,6c4,6 < 18+ < --- > 28+ > baba qu na er > beijing shanghai shenzhen yiyang [root@teacher-feng diff]# ============================================================== [root@teacher-feng diff]# diff -Nu hujie.txt hujie-2024.txt --- hujie.txt 2014-01-09 11:16:41.247531488 +0800 +++ hujie-2024.txt 2014-01-09 11:18:50.049531420 +0800 @@ -1,6 +1,6 @@ hujie -hulaoban -network +hulaoban --->ceo yiyang -18+ - +28+ +baba qu na er +beijing shanghai shenzhen yiyang [root@teacher-feng diff]# diff -u hujie.txt hujie-2024.txt --- hujie.txt 2014-01-09 11:16:41.247531488 +0800 +++ hujie-2024.txt 2014-01-09 11:18:50.049531420 +0800 @@ -1,6 +1,6 @@ hujie -hulaoban -network +hulaoban --->ceo yiyang -18+ - +28+ +baba qu na er +beijing shanghai shenzhen yiyang [root@teacher-feng diff]# [root@teacher-feng diff]# diff -u hujie.txt hujie-2024.txt --- hujie.txt 2014-01-09 11:16:41.247531488 +0800 +++ hujie-2024.txt 2014-01-09 11:18:50.049531420 +0800 @@ -1,6 +1,6 @@ hujie -hulaoban -network +hulaoban --->ceo yiyang -18+ - +28+ +baba qu na er +beijing shanghai shenzhen yiyang ========================================================== 生成补丁:[root@teacher-feng diff]# diff -u hujie.txt hujie-2024.txt >hujie-to-2024.patch [root@teacher-feng diff]# ls hujie-2024.txt hujie-to-2024.patch hujie.txt打补丁:[root@teacher-feng diff]# patch hujie.txt <hujie-to-2024.patch patching file hujie.txt [root@teacher-feng diff]# ============================================================ 验证是否成功: [root@teacher-feng diff]# diff -u hujie.txt hujie-2024.txt [root@teacher-feng diff]# =========================================================== -R 撤销打补丁(回滚): -R or --reverse [root@teacher-feng diff]# patch -R hujie.txt <hujie-to-2024.patch patching file hujie.txt [root@teacher-feng diff]#
=============================================================
------------------------指导老师(湖南双星科技发展有限公司副总经理)冯德勇
-------------------------网址:http://www.sxkeji.com.cn
------------电话:15874996921
------------QQ :695811769