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