Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15365810
  • 博文数量: 2005
  • 博客积分: 11986
  • 博客等级: 上将
  • 技术积分: 22535
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-17 13:56
文章分类

全部博文(2005)

文章存档

2014年(2)

2013年(2)

2012年(16)

2011年(66)

2010年(368)

2009年(743)

2008年(491)

2007年(317)

分类: LINUX

2008-08-07 11:04:36

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
阅读(953) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~