diff [option] file1 file2
按“行”比较两个文件的差异。可以比较文件或目录。
例如,比较compdir01和compdir03两个文件夹,忽略其中的.patch文件:
diff -u compdir01 compdir03 -x *.patch
-X patternfiles: 忽略patternfiles文件中指定的所有PATTERN
[root@ubuntu]others:$ cat patternfiles
main.c
backtrace.h
diff -u compdir01 compdir03 -X patternfiles
diff -u compdir01 compdir03 > compdir.patch
patch -pN < compdir.patch
其中N为需要剥掉的文件名中的目录级数,例如,compdir.patch文件中指明的文件名为:
记住,打patch的时候不要过分依赖patch命令,打完之后一定要检查代码。另外,尽量在原始项目中打patch,避免冲突。
quilt以栈的形式管理补丁,最先打上的补丁位于栈底,最后打上的补丁位于栈顶(top)。打patch的动作称为push,取消补丁的动作称为pop。就如下图所示,项目中有5个patch,最新的patch为e.patch,所以quilt将这个patch放在栈顶,通过维护这样一个结构,quilt可以继续打新patch或按顺序回退patch。
源代码的patch文件的先后顺序可以查看patches/目录下的series文件。[root@ubuntu]compdir01:$ quilt new 00-bt.patch
Patch 00-bt.patch is now on top
[root@ubuntu]compdir01:$ quilt add main.c
File main.c added to patch 00-bt.patch
这样,就新建了patch文件00-bt.patch,并关联了源文件main.c。注:如果要解除文件和当前patch的关联,使用quilt remove,如quilt remove main.c。修改main.c,增加几行打印信息。修改后,执行:
[root@ubuntu]compdir01:$ quilt refresh
Refreshed patch 00-bt.patch
在patches目录下就生成了00-bt.patch文件。
[root@ubuntu]compdir01:$ quilt new 02-bt-addr2name.patch
Patch 02-bt-addr2name.patch is now on top
[root@ubuntu]compdir01:$ quilt add main.c backtrace.h backtrace.c
File main.c added to patch 02-bt-addr2name.patch
File backtrace.h added to patch 02-bt-addr2name.patch
File backtrace.c added to patch 02-bt-addr2name.patch
此时修改代码,然后生成patch:
[root@ubuntu]compdir01:$ quilt refresh
Refreshed patch 02-bt-addr2name.patch
[root@ubuntu]compdir01:$ quilt new 03-bt-delcomments.patch
Patch 03-bt-delcomments.patch is now on top
[root@ubuntu]compdir01:$ quilt add backtrace.c
File backtrace.c added to patch 03-bt-delcomments.patch
[root@ubuntu]compdir01:$ quilt refresh
Refreshed patch 03-bt-delcomments.patch
[root@ubuntu]compdir01:$
[root@ubuntu]compdir01:$ quilt pop
Removing patch 03-bt-delcomments.patch
Restoring backtrace.c
Now at patch 02-bt-addr2name.patch
即现在将03-bt-delcomments.patch撤销了,代码目前处于打上02-bt-addr2name.patch的状态。
如果要撤销所有的patch,则执行
quilt pop -a
[root@ubuntu]compdir01:$ quilt push
要应用所有可用的patch,则执行
quilt push -a
[root@ubuntu]compdir01:$ quilt push patches/03-bt-delcomments.patch
Applying patch 00-bt.patch
patching file main.c
Applying patch 02-bt-addr2name.patch
patching file backtrace.c
patching file backtrace.h
patching file main.c
Applying patch 03-bt-delcomments.patch
patching file backtrace.c
Now at patch 03-bt-delcomments.patch
[root@ubuntu]compdir01:$ quilt pop patches/00-bt.patch
Removing patch 03-bt-delcomments.patch
Restoring backtrace.c
Removing patch 02-bt-addr2name.patch
Restoring backtrace.h
Restoring main.c
Restoring backtrace.c
Now at patch 00-bt.patch
可以看到,quilt会把中间所有需要pop或push的patch都应用上。另外,注意quilt pop patches/00-bt.patch命令效果是回退到打上00-bt.patch的状态,并不回退00-bt.patch本身。
[root@ubuntu]compdir01:$ quilt applied
00-bt.patch
02-bt-addr2name.patch
查看尚未应用的patch:
[root@ubuntu]compdir01:$ quilt unapplied
03-bt-delcomments.patch
[root@ubuntu]compdir01:$ quilt next
03-bt-delcomments.patch
查看前一个patch:
[root@ubuntu]compdir01:$ quilt previous
00-bt.patch
查看当前的patch:
[root@ubuntu]compdir01:$ quilt top
02-bt-addr2name.patch
[root@ubuntu]compdir01:$ quilt files
backtrace.c
backtrace.h
main.c
查看所有已应用的patch的关联文件:quilt files -a
[root@ubuntu]compdir01:$ quilt files patches/00-bt.patch
main.c
对应的,查看一个文件所关联的patch(已经应用的patches):
[root@ubuntu]compdir01:$ quilt patches backtrace.c
02-bt-addr2name.patch
03-bt-delcomments.patch
[root@ubuntu]compdir01:$ quilt revert main.c
Changes to backtrace.h in patch 02-bt-addr2name.patch reverted
[root@ubuntu]compdir03:$ quilt delete patches/02-bt-addr2name.patch
Removed patch 02-bt-addr2name.patch
这个patch不再在patches/series里面记录,并且pop和push的时候会被略过,如果是它是所有patch中间的某个patch,那在pop或push的时候可能会出错。所以这个命令一般用于删除最顶层的patch。
[root@ubuntu]compdir01:$ quilt rename -P patches/00-bt.patch patches/00-bt-addprint.patch
Patch 00-bt.patch renamed to 00-bt-addprint.patch
quilt edit file ...
这种修改源文件的方式和不使用quilt edit编辑的区别是,修改的文件同时与当前patch建立关联,不用再执行quilt add建立文件关联了。
[root@ubuntu]compdir01:$ quilt diff
会列出当前patch和上一个patch的区别,包括本地未提交的修改。
quilt diff -z backtrace.c -P patches/03-bt-delcomments.patch
[root@ubuntu]compdir03:$ quilt new pdir/02-dir-order.patch
Patch pdir/02-dir-order.patch is now on top
[root@ubuntu]compdir03:$ quilt add main.c
File main.c added to patch pdir/02-dir-order.patch