Chinaunix首页 | 论坛 | 博客
  • 博客访问: 466457
  • 博文数量: 115
  • 博客积分: 3777
  • 博客等级: 中校
  • 技术积分: 1070
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-07 09:20
文章分类

全部博文(115)

文章存档

2015年(1)

2013年(3)

2012年(26)

2011年(30)

2010年(34)

2009年(21)

我的朋友

分类:

2011-11-18 09:45:34

原文地址:diff和patch 作者:gliethttp

1. 单个文件
luther@gliethttp:~$ diff -ruNa hello.c hello.new.c >gliethttp_hello.diff
luther@gliethttp:~$ patch -p0 hello.c < gliethttp_hello.diff
2. 目录
luther@gliethttp:~$ diff -ruNa test1 test1_new > gliethttp_test_folder.diff
luther@gliethttp:~/test1$ patch -p1 <../gliethttp_test_folder.diff

diff:
输出格式:nomal格式,   -c上下输出格式,   -y并排输出格式,   -u统一输出格式
diff file1 file2   的输出:
<表示第一个文件file1
>表示第二个文件file2
? file1要如何变成file2呢:
ndm   表示file1的n行删除,后面的部分加到file2的m行后面;
ncm   表示file1的n行改成file2的m行那样;
nam   表示file1的n行后面的部分添加到file2的m行后面;

上下输出格式说明:
-   file1需要删除的
!   file1需要更改的
+   file1需要添加的

统一输出格式说明:
-   file1中需要删除的
+   file1中需要添加的
@@ -n,m +p,q @@
该比较块中,file1从n行开始,共m行,file2从p行开始,共q行;

一些选项:
-q   only report whether differ
-b   ignore space change,but can detect the difference of no space to have space
-w   ignore all spaces
-B   ignore blank lines
-r   enter subdir to diff

常用的命令格式:
diff -urN dir1 dir2 > dir.patch   产生patch的diff应采用统一格式u选项;

diff3 [option] file_chg1 file_org file_chg2 > newfile
将前后2个文件与当中的原始文件比较,输出结果.
-m选项可以合并文件,对于同一处的不同修改则报告冲突,显示为:<<<<||||====>>>>

patch [options] < patchfile
选项:
-p num   剥离前num个目录进行patch
-d dir   先进入dir目录,再patch
-R         逆向还原
如:
diff -u hello.c lohhe.c > hello.patch
patch -p0 < hello.patch
patch -R -p0 < hello.patch

diff -urN doc1 doc2 > doc.patch
rm doc2 -rf
patch -p0 < doc.patch
or
patch -d doc1 -p1 < doc.patch
阅读(539) | 评论(0) | 转发(0) |
0

上一篇:Maxima 矢量运算

下一篇:diff与patch

给主人留下些什么吧!~~