全部博文(534)
分类: LINUX
2007-09-28 17:17:53
9、如何自动忽略已经打过的补丁?
如果想让 patch 自动忽略这些已经打过的补丁呢?用 -N 选项
CODE:
[root@mail mine]# patch -N -i ../new.patch
patching file a
Reversed (or previously applied) patch detected! Skipping patch.
1 out of 1 hunk ignored -- saving rejects to file a.rej
patching file b
Reversed (or previously applied) patch detected! Skipping patch.
1 out of 1 hunk ignored -- saving rejects to file b.rej
The next patch would empty out the file c,
which is already empty! Skipping patch.
1 out of 1 hunk ignored -- saving rejects to file c.rej
[root@mail mine]#
可以看到即使用了 -N 或者 --forward ,还是会生成 .rej 文件。但不会再次提问了。
补丁工具包之 patchutils
patchutils 工具包
当你拿到一个补丁,你会想知道它究竟会修改那些文件 。或者你想知道该补丁文件是否会修改某个文件,这些应该怎么实现呢?
patchutils 是系统自带的一个工具包,顾名思义就是专门服务于 patch 文件的。它提供了很多的命令,例如 lsdiff、grepdiff 等。
CODE:
[bob@mail tmp]$ rpm -qi patchutils
Name : patchutils Relocations: (not relocateable)
Version :
Release : 1 Build Date: Sat 25 Jan 2003 01:59:14 PM CST
Install Date: Mon 17 Sep 2007 06:20:02 AM CST Build Host: porky.devel.redhat.com
Group : Applications/System Source RPM: patchutils-0.2.19-1.src.rpm
Size : 128817 License: GPL
Signature : DSA/SHA1, Mon 24 Feb 2003 02:43:34 PM CST, Key ID 219180cddb
Packager : Red Hat, Inc. <
URL :
Summary : A collection of programs for manipulating patch files
Description :
This is a collection of programs that can manipulate patch files in
a variety of ways, such as interpolating between two pre-patches,
combining two incremental patches, fixing line numbers in hand-edited
patches, and simply listing the files modified by a patch.
[bob@mail tmp]$
它提供的命令有
QUOTE:
combinediff (1) - create a cumulative unified patch from two incremental patches
dehtmldiff (1) - get usable diff from an HTML page
editdiff [rediff] (1) - fix offsets and counts of a hand-edited diff
espdiff (1) - apply the appropriate transformation to a set of patches
filterdiff (1) - extract or exclude diffs from a diff file
fixcvsdiff (1) - fix problematic diff files
flipdiff: nothing appropriate
grepdiff (1) - show files modified by a diff containing a regex
interdiff (1) - show differences between two diff files
lsdiff (1) - show which files are modified by a patch
recountdiff (1) - recompute patch counts and offsets
rediff (1) - fix offsets and counts of a hand-edited diff
splitdiff (1) - separate out incremental patches
unwrapdiff: nothing appropriate
我只介绍 lsdiff 和 grepdiff ,还有 splitdiff 和 combinediff 命令也可以学一下。
2、lsidff 命令
lsdiff 命令的常用选项有 :
-n :显示每个 hunk 定义在 patch 文件中的行号
-v :verbose 模式
--number-files :类似于 cat -n
--files= :只列出指定旧文件的 hunk
--strip= :输出文件名之前去掉路径前面的 n 个目录
--addprefix= :在输出文件名时加上指定前缀
-s :打印每个旧(源)文件的最终结果(增加/修改/删除)
-i :显示文件名路径匹配指定模式的 hunk
-x :排除文件名路径匹配指定模式的 hunk
--version :显示版本信息
--filter :模仿 filterdiff 的操作
3、lsdiff 应用实例
lsdiff 的默认输出
CODE:
[bob@mail tmp]$ lsdiff new.patch
/home/bob/old/a
/home/bob/old/b
/home/bob/old/c
[bob@mail tmp]$
lsdiff -n 的输出
CODE:
[bob@mail tmp]$ lsdiff new.patch -n
2 /home/bob/old/a
15 /home/bob/old/b
25 /home/bob/old/c
[bob@mail tmp]$
[bob@mail tmp]$ grep -n '/home/bob/old/' new.patch
1:diff -Nru /home/bob/old/a /home/bob/new/a
2:--- /home/bob/old/a 2007-09-20 23:30:43.000000000 +0800
14:diff -Nru /home/bob/old/b /home/bob/new/b
15:--- /home/bob/old/b 2007-09-21 16:07:28.000000000 +0800
24:diff -Nru /home/bob/old/c /home/bob/new/c
25:--- /home/bob/old/c 2007-09-23 21:27:50.000000000 +0800
[bob@mail tmp]$
lsdiff -v 的输出
CODE:
[bob@mail tmp]$ lsdiff -v new.patch
diff -Nru /home/bob/old/a /home/bob/new/a
/home/bob/old/a
diff -Nru /home/bob/old/b /home/bob/new/b
/home/bob/old/b
diff -Nru /home/bob/old/c /home/bob/new/c
/home/bob/old/c
[bob@mail tmp]$ lsdiff -v new.patch -n
diff -Nru /home/bob/old/a /home/bob/new/a
2 /home/bob/old/a
4 Hunk #1
diff -Nru /home/bob/old/b /home/bob/new/b
15 /home/bob/old/b
17 Hunk #1
diff -Nru /home/bob/old/c /home/bob/new/c
25 /home/bob/old/c
27 Hunk #1
[bob@mail tmp]$
lsidff -s 的输出
- :删除该文件。表示新目录下没有该文件,但旧目录有
! :修改该文件
+ :新增该文件。表示新目录下有该文件,但旧目录没有。
CODE:
[bob@mail bob]$ ll old
total 16
-rw-rw-r-- 1 bob bob 28 Sep 20 23:
-rw-rw-r-- 1 bob bob 23 Sep 21 16:07 b
-rw-r--r-- 1 root root 17 Sep 23 21:
-rw-rw-r-- 1 bob bob 3 Sep 24 11:23 e # 注释 :该文件不存在于 new/ 目录下,属于删除的。
[bob@mail bob]$
[bob@mail bob]$ ll new
total 12
-rw-rw-r-- 1 bob bob 42 Sep 24 11:
-rw-rw-r-- 1 bob bob 40 Sep 21 16:08 b
-rw-r--r-- 1 root root 0 Sep 23 21:
-rw-rw-r-- 1 bob bob 3 Sep 24 11:22 d # 注释 :该文件不存在于 old/ 目录下,属于新增加的。
[bob@mail bob]$
[bob@mail bob]$ lsdiff -s new.patch
! /home/bob/old/a
! /home/bob/old/b
! /home/bob/old/c
+ /home/bob/old/d
- /home/bob/old/e
[bob@mail bob]$
lsdiff -i 的输出
lsdiff -i 指定一个 shell wildcard ,用于匹配文件名(不匹配路径)
CODE:
[bob@mail tarball]$ lsdiff patch-
a/Documentation/Configure.help
a/Documentation/SubmittingDrivers
a/Documentation/kernel-parameters.txt
a/Documentation/networking/e1000.txt
[bob@mail tarball]$ lsdiff -i "e1000.txt" patch-2.4.35
[bob@mail tarball]$ lsdiff -i "*e1000.txt" patch-2.
a/Documentation/networking/e1000.txt
[bob@mail tarball]$
4、grepdiff 命令应用实例
grepdiff 和 lsdiff 不同的地方在于,它搜索的是修改的内容部分,而不是文件名。
而且 grepdiff 支持 regex ,而 lsdiff 只支持 shell wildcard
从下面的例子就可以知道了
CODE:
[n7css@monitor n7css]$ grepdiff '.*e1000.*' patch-
1 226 a/Documentation/networking/e1000.txt
2 1171 a/MAINTAINERS # 注释 :这个文件的文件名并没有 e1000 字样,但由于其中一个 hunk 含有 e1000 ,所以被列出来了。
3 2441 a/drivers/net/e1000/Makefile
4 2454 a/drivers/net/e1000/e1000.h
5 2812 a/drivers/net/e1000/e1000_ethtool.c
6 4900 a/drivers/net/e1000/e1000_hw.c
7 13336 a/drivers/net/e1000/e1000_hw.h
8 15482 a/drivers/net/e1000/e1000_main.c
9 21097 a/drivers/net/e1000/e1000_osdep.h
10 21236 a/drivers/net/e1000/e1000_param.c
11 21968 b/drivers/net/e1000/kcompat.c
12 22043 b/drivers/net/e1000/kcompat.h
[n7css@monitor n7css]$
但 lsdiff 则不会这样
CODE:
[n7css@monitor n7css]$ lsdiff -i "*e1000*" patch-
1 226 a/Documentation/networking/e1000.txt
2 2441 a/drivers/net/e1000/Makefile
3 2454 a/drivers/net/e1000/e1000.h
4 2812 a/drivers/net/e1000/e1000_ethtool.c
5 4900 a/drivers/net/e1000/e1000_hw.c
6 13336 a/drivers/net/e1000/e1000_hw.h
7 15482 a/drivers/net/e1000/e1000_main.c
8 21097 a/drivers/net/e1000/e1000_osdep.h
9 21236 a/drivers/net/e1000/e1000_param.c
10 21968 b/drivers/net/e1000/kcompat.c
11 22043 b/drivers/net/e1000/kcompat.h
[n7css@monitor n7css]$
可以看到 a/MATAINNANCE 文件没有被列出,因为它的文件名不含 e1000 字样