OSDN Git Service

Add Git official document to help
[tortoisegit/TortoiseGitJp.git] / doc / source / en / TortoiseGit / git_doc / gitdiffcore.html.xml
1 <?xml version="1.0" encoding="UTF-8"?>\r
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">\r
3 \r
4 <article lang="en" id="gitdiffcore(7)">\r
5 <articleinfo>\r
6     <title>gitdiffcore(7)</title>\r
7         <indexterm>\r
8                 <primary>gitdiffcore(7)</primary>\r
9         </indexterm>\r
10 </articleinfo>\r
11 <simplesect id="_name">\r
12 <title>NAME</title>\r
13 <simpara>gitdiffcore - Tweaking diff output (June 2005)</simpara>\r
14 </simplesect>\r
15 <simplesect id="_synopsis">\r
16 <title>SYNOPSIS</title>\r
17 <simpara><emphasis>git diff</emphasis> *</simpara>\r
18 </simplesect>\r
19 <simplesect id="_description">\r
20 <title>DESCRIPTION</title>\r
21 <simpara>The diff commands <emphasis>git-diff-index</emphasis>, <emphasis>git-diff-files</emphasis>, and <emphasis>git-diff-tree</emphasis>\r
22 can be told to manipulate differences they find in\r
23 unconventional ways before showing <emphasis>diff</emphasis> output.  The manipulation\r
24 is collectively called "diffcore transformation".  This short note\r
25 describes what they are and how to use them to produce <emphasis>diff</emphasis> output\r
26 that is easier to understand than the conventional kind.</simpara>\r
27 </simplesect>\r
28 <simplesect id="_the_chain_of_operation">\r
29 <title>The chain of operation</title>\r
30 <simpara>The <emphasis>git-diff-&#42;</emphasis> family works by first comparing two sets of\r
31 files:</simpara>\r
32 <itemizedlist>\r
33 <listitem>\r
34 <simpara>\r
35 <emphasis>git-diff-index</emphasis> compares contents of a "tree" object and the\r
36    working directory (when <emphasis>--cached</emphasis> flag is not used) or a\r
37    "tree" object and the index file (when <emphasis>--cached</emphasis> flag is\r
38    used);\r
39 </simpara>\r
40 </listitem>\r
41 <listitem>\r
42 <simpara>\r
43 <emphasis>git-diff-files</emphasis> compares contents of the index file and the\r
44    working directory;\r
45 </simpara>\r
46 </listitem>\r
47 <listitem>\r
48 <simpara>\r
49 <emphasis>git-diff-tree</emphasis> compares contents of two "tree" objects;\r
50 </simpara>\r
51 </listitem>\r
52 </itemizedlist>\r
53 <simpara>In all of these cases, the commands themselves first optionally limit\r
54 the two sets of files by any pathspecs given on their command-lines,\r
55 and compare corresponding paths in the two resulting sets of files.</simpara>\r
56 <simpara>The pathspecs are used to limit the world diff operates in.  They remove\r
57 the filepairs outside the specified sets of pathnames.  E.g. If the\r
58 input set of filepairs included:</simpara>\r
59 <literallayout>:100644 100644 bcd1234... 0123456... M junkfile</literallayout>\r
60 <simpara>but the command invocation was <literal>git diff-files myfile</literal>, then the\r
61 junkfile entry would be removed from the list because only "myfile"\r
62 is under consideration.</simpara>\r
63 <simpara>The result of comparison is passed from these commands to what is\r
64 internally called "diffcore", in a format similar to what is output\r
65 when the -p option is not used.  E.g.</simpara>\r
66 <literallayout>in-place edit  :100644 100644 bcd1234... 0123456... M file0\r
67 create         :000000 100644 0000000... 1234567... A file4\r
68 delete         :100644 000000 1234567... 0000000... D file5\r
69 unmerged       :000000 000000 0000000... 0000000... U file6</literallayout>\r
70 <simpara>The diffcore mechanism is fed a list of such comparison results\r
71 (each of which is called "filepair", although at this point each\r
72 of them talks about a single file), and transforms such a list\r
73 into another list.  There are currently 5 such transformations:</simpara>\r
74 <itemizedlist>\r
75 <listitem>\r
76 <simpara>\r
77 diffcore-break\r
78 </simpara>\r
79 </listitem>\r
80 <listitem>\r
81 <simpara>\r
82 diffcore-rename\r
83 </simpara>\r
84 </listitem>\r
85 <listitem>\r
86 <simpara>\r
87 diffcore-merge-broken\r
88 </simpara>\r
89 </listitem>\r
90 <listitem>\r
91 <simpara>\r
92 diffcore-pickaxe\r
93 </simpara>\r
94 </listitem>\r
95 <listitem>\r
96 <simpara>\r
97 diffcore-order\r
98 </simpara>\r
99 </listitem>\r
100 </itemizedlist>\r
101 <simpara>These are applied in sequence.  The set of filepairs <emphasis>git-diff-&#42;</emphasis>\r
102 commands find are used as the input to diffcore-break, and\r
103 the output from diffcore-break is used as the input to the\r
104 next transformation.  The final result is then passed to the\r
105 output routine and generates either diff-raw format (see Output\r
106 format sections of the manual for <emphasis>git-diff-&#42;</emphasis> commands) or\r
107 diff-patch format.</simpara>\r
108 </simplesect>\r
109 <simplesect id="_diffcore_break_for_splitting_up_complete_rewrites">\r
110 <title>diffcore-break: For Splitting Up "Complete Rewrites"</title>\r
111 <simpara>The second transformation in the chain is diffcore-break, and is\r
112 controlled by the -B option to the <emphasis>git-diff-&#42;</emphasis> commands.  This is\r
113 used to detect a filepair that represents "complete rewrite" and\r
114 break such filepair into two filepairs that represent delete and\r
115 create.  E.g.  If the input contained this filepair:</simpara>\r
116 <literallayout>:100644 100644 bcd1234... 0123456... M file0</literallayout>\r
117 <simpara>and if it detects that the file "file0" is completely rewritten,\r
118 it changes it to:</simpara>\r
119 <literallayout>:100644 000000 bcd1234... 0000000... D file0\r
120 :000000 100644 0000000... 0123456... A file0</literallayout>\r
121 <simpara>For the purpose of breaking a filepair, diffcore-break examines\r
122 the extent of changes between the contents of the files before\r
123 and after modification (i.e. the contents that have "bcd1234&#8230;"\r
124 and "0123456&#8230;" as their SHA1 content ID, in the above\r
125 example).  The amount of deletion of original contents and\r
126 insertion of new material are added together, and if it exceeds\r
127 the "break score", the filepair is broken into two.  The break\r
128 score defaults to 50% of the size of the smaller of the original\r
129 and the result (i.e. if the edit shrinks the file, the size of\r
130 the result is used; if the edit lengthens the file, the size of\r
131 the original is used), and can be customized by giving a number\r
132 after "-B" option (e.g. "-B75" to tell it to use 75%).</simpara>\r
133 </simplesect>\r
134 <simplesect id="_diffcore_rename_for_detection_renames_and_copies">\r
135 <title>diffcore-rename: For Detection Renames and Copies</title>\r
136 <simpara>This transformation is used to detect renames and copies, and is\r
137 controlled by the -M option (to detect renames) and the -C option\r
138 (to detect copies as well) to the <emphasis>git-diff-&#42;</emphasis> commands.  If the\r
139 input contained these filepairs:</simpara>\r
140 <literallayout>:100644 000000 0123456... 0000000... D fileX\r
141 :000000 100644 0000000... 0123456... A file0</literallayout>\r
142 <simpara>and the contents of the deleted file fileX is similar enough to\r
143 the contents of the created file file0, then rename detection\r
144 merges these filepairs and creates:</simpara>\r
145 <literallayout>:100644 100644 0123456... 0123456... R100 fileX file0</literallayout>\r
146 <simpara>When the "-C" option is used, the original contents of modified files,\r
147 and deleted files (and also unmodified files, if the\r
148 "--find-copies-harder" option is used) are considered as candidates\r
149 of the source files in rename/copy operation.  If the input were like\r
150 these filepairs, that talk about a modified file fileY and a newly\r
151 created file file0:</simpara>\r
152 <literallayout>:100644 100644 0123456... 1234567... M fileY\r
153 :000000 100644 0000000... bcd3456... A file0</literallayout>\r
154 <simpara>the original contents of fileY and the resulting contents of\r
155 file0 are compared, and if they are similar enough, they are\r
156 changed to:</simpara>\r
157 <literallayout>:100644 100644 0123456... 1234567... M fileY\r
158 :100644 100644 0123456... bcd3456... C100 fileY file0</literallayout>\r
159 <simpara>In both rename and copy detection, the same "extent of changes"\r
160 algorithm used in diffcore-break is used to determine if two\r
161 files are "similar enough", and can be customized to use\r
162 a similarity score different from the default of 50% by giving a\r
163 number after the "-M" or "-C" option (e.g. "-M8" to tell it to use\r
164 8/10 = 80%).</simpara>\r
165 <simpara>Note.  When the "-C" option is used with <literal>--find-copies-harder</literal>\r
166 option, <emphasis>git-diff-&#42;</emphasis> commands feed unmodified filepairs to\r
167 diffcore mechanism as well as modified ones.  This lets the copy\r
168 detector consider unmodified files as copy source candidates at\r
169 the expense of making it slower.  Without <literal>--find-copies-harder</literal>,\r
170 <emphasis>git-diff-&#42;</emphasis> commands can detect copies only if the file that was\r
171 copied happened to have been modified in the same changeset.</simpara>\r
172 </simplesect>\r
173 <simplesect id="_diffcore_merge_broken_for_putting_complete_rewrites_back_together">\r
174 <title>diffcore-merge-broken: For Putting "Complete Rewrites" Back Together</title>\r
175 <simpara>This transformation is used to merge filepairs broken by\r
176 diffcore-break, and not transformed into rename/copy by\r
177 diffcore-rename, back into a single modification.  This always\r
178 runs when diffcore-break is used.</simpara>\r
179 <simpara>For the purpose of merging broken filepairs back, it uses a\r
180 different "extent of changes" computation from the ones used by\r
181 diffcore-break and diffcore-rename.  It counts only the deletion\r
182 from the original, and does not count insertion.  If you removed\r
183 only 10 lines from a 100-line document, even if you added 910\r
184 new lines to make a new 1000-line document, you did not do a\r
185 complete rewrite.  diffcore-break breaks such a case in order to\r
186 help diffcore-rename to consider such filepairs as candidate of\r
187 rename/copy detection, but if filepairs broken that way were not\r
188 matched with other filepairs to create rename/copy, then this\r
189 transformation merges them back into the original\r
190 "modification".</simpara>\r
191 <simpara>The "extent of changes" parameter can be tweaked from the\r
192 default 80% (that is, unless more than 80% of the original\r
193 material is deleted, the broken pairs are merged back into a\r
194 single modification) by giving a second number to -B option,\r
195 like these:</simpara>\r
196 <itemizedlist>\r
197 <listitem>\r
198 <simpara>\r
199 -B50/60 (give 50% "break score" to diffcore-break, use 60%\r
200   for diffcore-merge-broken).\r
201 </simpara>\r
202 </listitem>\r
203 <listitem>\r
204 <simpara>\r
205 -B/60 (the same as above, since diffcore-break defaults to 50%).\r
206 </simpara>\r
207 </listitem>\r
208 </itemizedlist>\r
209 <simpara>Note that earlier implementation left a broken pair as a separate\r
210 creation and deletion patches.  This was an unnecessary hack and\r
211 the latest implementation always merges all the broken pairs\r
212 back into modifications, but the resulting patch output is\r
213 formatted differently for easier review in case of such\r
214 a complete rewrite by showing the entire contents of old version\r
215 prefixed with <emphasis>-</emphasis>, followed by the entire contents of new\r
216 version prefixed with <emphasis>+</emphasis>.</simpara>\r
217 </simplesect>\r
218 <simplesect id="_diffcore_pickaxe_for_detecting_addition_deletion_of_specified_string">\r
219 <title>diffcore-pickaxe: For Detecting Addition/Deletion of Specified String</title>\r
220 <simpara>This transformation is used to find filepairs that represent\r
221 changes that touch a specified string, and is controlled by the\r
222 -S option and the <literal>--pickaxe-all</literal> option to the <emphasis>git-diff-&#42;</emphasis>\r
223 commands.</simpara>\r
224 <simpara>When diffcore-pickaxe is in use, it checks if there are\r
225 filepairs whose "original" side has the specified string and\r
226 whose "result" side does not.  Such a filepair represents "the\r
227 string appeared in this changeset".  It also checks for the\r
228 opposite case that loses the specified string.</simpara>\r
229 <simpara>When <literal>--pickaxe-all</literal> is not in effect, diffcore-pickaxe leaves\r
230 only such filepairs that touch the specified string in its\r
231 output.  When <literal>--pickaxe-all</literal> is used, diffcore-pickaxe leaves all\r
232 filepairs intact if there is such a filepair, or makes the\r
233 output empty otherwise.  The latter behaviour is designed to\r
234 make reviewing of the changes in the context of the whole\r
235 changeset easier.</simpara>\r
236 </simplesect>\r
237 <simplesect id="_diffcore_order_for_sorting_the_output_based_on_filenames">\r
238 <title>diffcore-order: For Sorting the Output Based on Filenames</title>\r
239 <simpara>This is used to reorder the filepairs according to the user&#8217;s\r
240 (or project&#8217;s) taste, and is controlled by the -O option to the\r
241 <emphasis>git-diff-&#42;</emphasis> commands.</simpara>\r
242 <simpara>This takes a text file each of whose lines is a shell glob\r
243 pattern.  Filepairs that match a glob pattern on an earlier line\r
244 in the file are output before ones that match a later line, and\r
245 filepairs that do not match any glob pattern are output last.</simpara>\r
246 <simpara>As an example, a typical orderfile for the core git probably\r
247 would look like this:</simpara>\r
248 <literallayout>README\r
249 Makefile\r
250 Documentation\r
251 *.h\r
252 *.c\r
253 t</literallayout>\r
254 </simplesect>\r
255 <simplesect id="_see_also">\r
256 <title>SEE ALSO</title>\r
257 <simpara><xref linkend="git-diff(1)"/>,\r
258 <xref linkend="git-diff-files(1)"/>,\r
259 <xref linkend="git-diff-index(1)"/>,\r
260 <xref linkend="git-diff-tree(1)"/>,\r
261 <xref linkend="git-format-patch(1)"/>,\r
262 <xref linkend="git-log(1)"/>,\r
263 <xref linkend="gitglossary(7)"/>,\r
264 <ulink url="user-manual.html">The Git User&#8217;s Manual</ulink></simpara>\r
265 </simplesect>\r
266 <simplesect id="_git">\r
267 <title>GIT</title>\r
268 <simpara>Part of the <xref linkend="git(1)"/> suite.</simpara>\r
269 </simplesect>\r
270 </article>\r