1FILTERDIFF(1) Man pages FILTERDIFF(1)
2
3
4
6 filterdiff - extract or exclude diffs from a diff file
7
9 filterdiff [-i PATTERN] [-p n] [--strip=n] [--addprefix=PREFIX]
10 [-x PATTERN] [--verbose] [-v] [-z] [[-# RANGE]
11 [--hunks=RANGE]] [--lines=RANGE] [--files=RANGE]
12 [--annotate] [--format=FORMAT] [--as-numbered-lines=WHEN]
13 [--remove-timestamps] [file...]
14
15 filterdiff {[--help] [--version] [--list] [--grep ...]}
16
18 You can use filterdiff to obtain a patch that applies to files matching
19 the shell wildcard PATTERN from a larger collection of patches. For
20 example, to see the patches in patch-2.4.3.gz that apply to all files
21 called lp.c:
22
23 filterdiff -z -i '*/lp.c' patch-2.4.3.gz
24
25 If neither -i nor -x options are given, -i '*' is assumed. This way
26 filterdiff can be used to clean up an existing diff file, removing
27 redundant lines from the beginning (eg. the text from the mail body) or
28 between the chunks (eg. in CVS diffs). To extract pure patch data, use
29 a command like this:
30
31 filterdiff message-with-diff-in-the-body > patch
32
33 Note that the interpretation of the shell wildcard pattern does not
34 count slash characters or periods as special (in other words, no flags
35 are given to fnmatch). This is so that “*/basename”-type patterns can
36 be given without limiting the number of pathname components.
37
38 You can use both unified and context format diffs with this program.
39
41 -i PATTERN
42 Include only files matching PATTERN. All other lines in the
43 input are suppressed.
44
45 -x PATTERN
46 Exclude files matching PATTERN. All other lines in the input are
47 displayed.
48
49 -p n When matching, ignore the first n components of the pathname.
50
51 -# RANGE | --hunks=RANGE
52 Only include hunks within the specified RANGE. Hunks are
53 numbered from 1, and the range is a comma-separated list of
54 numbers or “first-last” spans; either the first or the last in
55 the span may be omitted to indicate no limit in that direction.
56
57 --lines=RANGE
58 Only include hunks that contain lines from the original file
59 that lie within the specified RANGE. Lines are numbered from 1,
60 and the range is a comma-separated list of numbers or
61 “first-last” spans; either the first or the last in the span may
62 be omitted to indicate no limit in that direction.
63
64 --files=RANGE
65 Only include files indicated by the specified RANGE. Files are
66 numbered from 1 in the order they appear in the patch input, and
67 the range is a comma-separated list of numbers or “first-last”
68 spans; either the first or the last in the span may be omitted
69 to indicate no limit in that direction.
70
71 --annotate
72 Annotate each hunk with the filename and hunk number.
73
74 --format=unified|context
75 Use specified output format.
76
77 --strip=n
78 Remove the first n components of pathnames in the output.
79
80 --addprefix=PREFIX
81 Prefix pathnames in the output by PREFIX.
82
83 --as-numbered-lines=before|after
84 Instead of a patch fragment, display the lines of the selected
85 hunks with the line number of the file before (or after) the
86 patch is applied, followed by a TAB character and a colon, at
87 the beginning of each line. Each hunk except the first will have
88 a line consisting of “...” before it.
89
90 --remove-timestamps
91 Do not include file timestamps in the output.
92
93 -v, --verbose
94 Always show non-diff lines in the output. By default, non-diff
95 lines are only shown when excluding a filename pattern.
96
97 -z Decompress files with extensions .gz and .bz2.
98
99 --help Display a short usage message.
100
101 --version
102 Display the version number of filterdiff.
103
104 --list Behave like lsdiff(1) instead.
105
106 --grep Behave like grepdiff(1) instead.
107
109 To see all patch hunks that affect the first five lines of a C file:
110
111 filterdiff -i '*.c' --lines=-5 < patch
112
113 To see the first hunk of each file patch, use:
114
115 filterdiff -#1 patchfile
116
117 To see patches modifying a ChangeLog file in a subdirectory, use:
118
119 filterdiff -p1 Changelog
120
121 To see the complete patches for each patch that modifies line 1 of the
122 original file, use:
123
124 filterdiff --lines=1 patchfile | lsdiff | \
125 xargs -rn1 filterdiff patchfile -i
126
127 To see all but the first hunk of a particular patch, you might use:
128
129 filterdiff -p1 -i file.c -#2- foo-patch
130
131 If you have a very specific list of hunks in a patch that you want to
132 see, list them:
133
134 filterdiff -#1,2,5-8,10,12,27-
135
136 To see the lines of the files that would be patched as they will appear
137 after the patch is applied, use:
138
139 filterdiff --as-numbered-lines=after patch.file
140
141 You can see the same context before the patch is applied with:
142
143 filterdiff --as-numbered-lines=before
144 patch.file
145
146 Filterdiff can also be used to convert between unified and context
147 format diffs:
148
149 filterdiff -v --format=unified context.diff
150
152 lsdiff(1), grepdiff(1)
153
155 Tim Waugh <twaugh@redhat.com>.
156
157
158
159patchutils 7 May 2004 FILTERDIFF(1)