diff [option] file1 file2按“行”比较两个文件的差异。可以比较文件或目录。
例如,比较compdir01和compdir03两个文件夹,忽略其中的.patch文件:
<span style="white-space:pre"> </span>diff -u compdir01 compdir03 -x *.patch-X patternfiles: 忽略patternfiles文件中指定的所有PATTERN
[zhenfg@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文件。<pre name="code" class="plain">[zhenfg@ubuntu]compdir01:$ quilt new 00-bt.patch Patch 00-bt.patch is now on top [zhenfg@ubuntu]compdir01:$ quilt add main.c File main.c added to patch 00-bt.patch这样,就新建了patch文件00-bt.patch,并关联了源文件main.c。
[zhenfg@ubuntu]compdir01:$ quilt refresh Refreshed patch 00-bt.patch在patches目录下就生成了00-bt.patch文件。
[zhenfg@ubuntu]compdir01:$ quilt new 02-bt-addr2name.patch Patch 02-bt-addr2name.patch is now on top [zhenfg@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:
[zhenfg@ubuntu]compdir01:$ quilt refresh Refreshed patch 02-bt-addr2name.patch
[zhenfg@ubuntu]compdir01:$ quilt new 03-bt-delcomments.patch Patch 03-bt-delcomments.patch is now on top [zhenfg@ubuntu]compdir01:$ quilt add backtrace.c File backtrace.c added to patch 03-bt-delcomments.patch [zhenfg@ubuntu]compdir01:$ quilt refresh Refreshed patch 03-bt-delcomments.patch [zhenfg@ubuntu]compdir01:$
[zhenfg@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
[zhenfg@ubuntu]compdir01:$ quilt push
要应用所有可用的patch,则执行
quilt push -a
[zhenfg@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
[zhenfg@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本身。
[zhenfg@ubuntu]compdir01:$ quilt applied 00-bt.patch 02-bt-addr2name.patch查看尚未应用的patch:
[zhenfg@ubuntu]compdir01:$ quilt unapplied 03-bt-delcomments.patch
[zhenfg@ubuntu]compdir01:$ quilt next 03-bt-delcomments.patch查看前一个patch:
[zhenfg@ubuntu]compdir01:$ quilt previous 00-bt.patch查看当前的patch:
[zhenfg@ubuntu]compdir01:$ quilt top 02-bt-addr2name.patch
[zhenfg@ubuntu]compdir01:$ quilt files backtrace.c backtrace.h main.c查看所有已应用的patch的关联文件:quilt files -a
[zhenfg@ubuntu]compdir01:$ quilt files patches/00-bt.patch main.c对应的,查看一个文件所关联的patch(已经应用的patches):
[zhenfg@ubuntu]compdir01:$ quilt patches backtrace.c 02-bt-addr2name.patch 03-bt-delcomments.patch
[zhenfg@ubuntu]compdir01:$ quilt revert main.c Changes to backtrace.h in patch 02-bt-addr2name.patch reverted
[zhenfg@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。
[zhenfg@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建立文件关联了。
[zhenfg@ubuntu]compdir01:$ quilt diff会列出当前patch和上一个patch的区别,包括本地未提交的修改。
quilt diff -z backtrace.c -P patches/03-bt-delcomments.patch
[zhenfg@ubuntu]compdir03:$ quilt new pdir/02-dir-order.patch Patch pdir/02-dir-order.patch is now on top [zhenfg@ubuntu]compdir03:$ quilt add main.c File main.c added to patch pdir/02-dir-order.patch