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

NAME

6       gitdiffcore - Tweaking diff output
7

SYNOPSIS

9       git diff *
10
11

DESCRIPTION

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

THE CHAIN OF OPERATION

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

DIFFCORE-BREAK: FOR SPLITTING UP COMPLETE REWRITES""

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

DIFFCORE-RENAME: FOR DETECTION RENAMES AND COPIES

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

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

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

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

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

DIFFCORE-ORDER: FOR SORTING THE OUTPUT BASED ON FILENAMES

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

SEE ALSO

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

GIT

237       Part of the git(1) suite.
238

NOTES

240        1. The Git User’s Manual
241           file:///usr/share/doc/git-1.8.3.1/user-manual.html
242
243
244
245Git 1.8.3.1                       11/19/2018                    GITDIFFCORE(7)
Impressum