1GITDIFFCORE(7)                    Git Manual                    GITDIFFCORE(7)
2
3
4

NAME

6       gitdiffcore - Tweaking diff output
7

SYNOPSIS

9       git diff *
10

DESCRIPTION

12       The diff commands git diff-index, git diff-files, and git diff-tree can
13       be told to manipulate differences they find in unconventional ways
14       before showing diff output. The manipulation is collectively called
15       "diffcore transformation". This short note describes what they are and
16       how to use them to produce diff output that is easier to understand
17       than the conventional kind.
18

THE CHAIN OF OPERATION

20       The git diff-* family works by first comparing two sets of files:
21
22       ·    git diff-index compares contents of a "tree" object and the
23           working directory (when --cached flag is not used) or a "tree"
24           object and the index file (when --cached flag is used);
25
26       ·    git diff-files compares contents of the index file and the working
27           directory;
28
29       ·    git diff-tree compares contents of two "tree" objects;
30
31       In all of these cases, the commands themselves first optionally limit
32       the two sets of files by any pathspecs given on their command-lines,
33       and compare corresponding paths in the two resulting sets of files.
34
35       The pathspecs are used to limit the world diff operates in. They remove
36       the filepairs outside the specified sets of pathnames. E.g. If the
37       input set of filepairs included:
38
39           :100644 100644 bcd1234... 0123456... M junkfile
40
41
42       but the command invocation was git diff-files myfile, then the junkfile
43       entry would be removed from the list because only "myfile" is under
44       consideration.
45
46       The result of comparison is passed from these commands to what is
47       internally called "diffcore", in a format similar to what is output
48       when the -p option is not used. E.g.
49
50           in-place edit  :100644 100644 bcd1234... 0123456... M file0
51           create         :000000 100644 0000000... 1234567... A file4
52           delete         :100644 000000 1234567... 0000000... D file5
53           unmerged       :000000 000000 0000000... 0000000... U file6
54
55
56       The diffcore mechanism is fed a list of such comparison results (each
57       of which is called "filepair", although at this point each of them
58       talks about a single file), and transforms such a list into another
59       list. There are currently 5 such transformations:
60
61       ·   diffcore-break
62
63       ·   diffcore-rename
64
65       ·   diffcore-merge-broken
66
67       ·   diffcore-pickaxe
68
69       ·   diffcore-order
70
71       These are applied in sequence. The set of filepairs git diff-* commands
72       find are used as the input to diffcore-break, and the output from
73       diffcore-break is used as the input to the next transformation. The
74       final result is then passed to the output routine and generates either
75       diff-raw format (see Output format sections of the manual for git
76       diff-* commands) or diff-patch format.
77

DIFFCORE-BREAK: FOR SPLITTING UP COMPLETE REWRITES""

79       The second transformation in the chain is diffcore-break, and is
80       controlled by the -B option to the git diff-* commands. This is used to
81       detect a filepair that represents "complete rewrite" and break such
82       filepair into two filepairs that represent delete and create. E.g. If
83       the input contained this filepair:
84
85           :100644 100644 bcd1234... 0123456... M file0
86
87
88       and if it detects that the file "file0" is completely rewritten, it
89       changes it to:
90
91           :100644 000000 bcd1234... 0000000... D file0
92           :000000 100644 0000000... 0123456... A file0
93
94
95       For the purpose of breaking a filepair, diffcore-break examines the
96       extent of changes between the contents of the files before and after
97       modification (i.e. the contents that have "bcd1234..." and "0123456..."
98       as their SHA1 content ID, in the above example). The amount of deletion
99       of original contents and insertion of new material are added together,
100       and if it exceeds the "break score", the filepair is broken into two.
101       The break score defaults to 50% of the size of the smaller of the
102       original and the result (i.e. if the edit shrinks the file, the size of
103       the result is used; if the edit lengthens the file, the size of the
104       original is used), and can be customized by giving a number after "-B"
105       option (e.g. "-B75" to tell it to use 75%).
106

DIFFCORE-RENAME: FOR DETECTION RENAMES AND COPIES

108       This transformation is used to detect renames and copies, and is
109       controlled by the -M option (to detect renames) and the -C option (to
110       detect copies as well) to the git diff-* commands. If the input
111       contained these filepairs:
112
113           :100644 000000 0123456... 0000000... D fileX
114           :000000 100644 0000000... 0123456... A file0
115
116
117       and the contents of the deleted file fileX is similar enough to the
118       contents of the created file file0, then rename detection merges these
119       filepairs and creates:
120
121           :100644 100644 0123456... 0123456... R100 fileX file0
122
123
124       When the "-C" option is used, the original contents of modified files,
125       and deleted files (and also unmodified files, if the
126       "--find-copies-harder" option is used) are considered as candidates of
127       the source files in rename/copy operation. If the input were like these
128       filepairs, that talk about a modified file fileY and a newly created
129       file file0:
130
131           :100644 100644 0123456... 1234567... M fileY
132           :000000 100644 0000000... bcd3456... A file0
133
134
135       the original contents of fileY and the resulting contents of file0 are
136       compared, and if they are similar enough, they are changed to:
137
138           :100644 100644 0123456... 1234567... M fileY
139           :100644 100644 0123456... bcd3456... C100 fileY file0
140
141
142       In both rename and copy detection, the same "extent of changes"
143       algorithm used in diffcore-break is used to determine if two files are
144       "similar enough", and can be customized to use a similarity score
145       different from the default of 50% by giving a number after the "-M" or
146       "-C" option (e.g. "-M8" to tell it to use 8/10 = 80%).
147
148       Note. When the "-C" option is used with --find-copies-harder option,
149       git diff-* commands feed unmodified filepairs to diffcore mechanism as
150       well as modified ones. This lets the copy detector consider unmodified
151       files as copy source candidates at the expense of making it slower.
152       Without --find-copies-harder, git diff-* commands can detect copies
153       only if the file that was copied happened to have been modified in the
154       same changeset.
155

DIFFCORE-MERGE-BROKEN: FOR PUTTING COMPLETE REWRITES" BACK TOGETHER"

157       This transformation is used to merge filepairs broken by
158       diffcore-break, and not transformed into rename/copy by
159       diffcore-rename, back into a single modification. This always runs when
160       diffcore-break is used.
161
162       For the purpose of merging broken filepairs back, it uses a different
163       "extent of changes" computation from the ones used by diffcore-break
164       and diffcore-rename. It counts only the deletion from the original, and
165       does not count insertion. If you removed only 10 lines from a 100-line
166       document, even if you added 910 new lines to make a new 1000-line
167       document, you did not do a complete rewrite. diffcore-break breaks such
168       a case in order to help diffcore-rename to consider such filepairs as
169       candidate of rename/copy detection, but if filepairs broken that way
170       were not matched with other filepairs to create rename/copy, then this
171       transformation merges them back into the original "modification".
172
173       The "extent of changes" parameter can be tweaked from the default 80%
174       (that is, unless more than 80% of the original material is deleted, the
175       broken pairs are merged back into a single modification) by giving a
176       second number to -B option, like these:
177
178       ·   -B50/60 (give 50% "break score" to diffcore-break, use 60% for
179           diffcore-merge-broken).
180
181       ·   -B/60 (the same as above, since diffcore-break defaults to 50%).
182
183       Note that earlier implementation left a broken pair as a separate
184       creation and deletion patches. This was an unnecessary hack and the
185       latest implementation always merges all the broken pairs back into
186       modifications, but the resulting patch output is formatted differently
187       for easier review in case of such a complete rewrite by showing the
188       entire contents of old version prefixed with -, followed by the entire
189       contents of new version prefixed with +.
190

DIFFCORE-PICKAXE: FOR DETECTING ADDITION/DELETION OF SPECIFIED STRING

192       This transformation is used to find filepairs that represent changes
193       that touch a specified string, and is controlled by the -S option and
194       the --pickaxe-all option to the git diff-* commands.
195
196       When diffcore-pickaxe is in use, it checks if there are filepairs whose
197       "result" side and whose "origin" side have different number of
198       specified string. Such a filepair represents "the string appeared in
199       this changeset". It also checks for the opposite case that loses the
200       specified string.
201
202       When --pickaxe-all is not in effect, diffcore-pickaxe leaves only such
203       filepairs that touch the specified string in its output. When
204       --pickaxe-all is used, diffcore-pickaxe leaves all filepairs intact if
205       there is such a filepair, or makes the output empty otherwise. The
206       latter behaviour is designed to make reviewing of the changes in the
207       context of the whole changeset easier.
208

DIFFCORE-ORDER: FOR SORTING THE OUTPUT BASED ON FILENAMES

210       This is used to reorder the filepairs according to the user’s (or
211       project’s) taste, and is controlled by the -O option to the git diff-*
212       commands.
213
214       This takes a text file each of whose lines is a shell glob pattern.
215       Filepairs that match a glob pattern on an earlier line in the file are
216       output before ones that match a later line, and filepairs that do not
217       match any glob pattern are output last.
218
219       As an example, a typical orderfile for the core git probably would look
220       like this:
221
222           README
223           Makefile
224           Documentation
225           *.h
226           *.c
227           t
228
229

SEE ALSO

231       git-diff(1), git-diff-files(1), git-diff-index(1), git-diff-tree(1),
232       git-format-patch(1), git-log(1), gitglossary(7), The Git User’s
233       Manual[1]
234

GIT

236       Part of the git(1) suite.
237

NOTES

239        1. The Git User’s Manual
240           file:///usr/share/doc/git-1.7.4.4/user-manual.html
241
242
243
244Git 1.7.4.4                       04/11/2011                    GITDIFFCORE(7)
Impressum