13:32 ,ˆl–Ðz¾”ËmJeAàq¶ÔÅ£Á „@п_‡I|¥ŠèªÆÅ+"gitdiffcore(7) ============== NAME ---- gitdiffcore - Tweaking diff output SYNOPSIS -------- [verse] 'git diff' * DESCRIPTION ----------- The diff commands 'git diff-index', 'git diff-files', and 'git diff-tree' can be told to manipulate differences they find in unconventional ways before showing 'diff' output. The manipulation is collectively called "diffcore transformation". This short note describes what they are and how to use them to produce 'diff' output that is easier to understand than the conventional kind. The chain of operation ---------------------- The 'git diff-{asterisk}' family works by first comparing two sets of files: - 'git diff-index' compares contents of a "tree" object and the working directory (when '\--cached' flag is not used) or a "tree" object and the index file (when '\--cached' flag is used); - 'git diff-files' compares contents of the index file and the working directory; - 'git diff-tree' compares contents of two "tree" objects; In all of these cases, the commands themselves first optionally limit the two sets of files by any pathspecs given on their command-lines, and compare corresponding paths in the two resulting sets of files. The pathspecs are used to limit the world diff operates in. They remove the filepairs outside the specified sets of pathnames. E.g. If the input set of filepairs included: ------------------------------------------------ :100644 100644 bcd1234... 0123456... M junkfile ------------------------------------------------ but the command invocation was `git diff-files myfile`, then the junkfile entry would be removed from the list because only "myfile" is under consideration. The result of comparison is passed from these commands to what is internally called "diffcore", in a format similar to what is output when the -p option is not used. E.g. ------------------------------------------------ in-place edit :100644 100644 bcd1234... 0123456... M file0 create :000000 100644 0000000... 1234567... A file4 delete :100644 000000 1234567... 0000000... D file5 unmerged :000000 000000 0000000... 0000000... U file6 ------------------------------------------------ The diffcore mechanism is fed a list of such comparison results (each of which is called "filepair", although at this point each of them talks about a single file), and transforms such a list into another list. There are currently 5 such transformations: - diffcore-break - diffcore-rename - diffcore-merge-broken - diffcore-pickaxe - diffcore-order These are applied in sequence. The set of filepairs 'git diff-{asterisk}' commands find are used as the input to diffcore-break, and the output from diffcore-break is used as the input to the next transformation. The final result is then passed to the output routine and generates either diff-raw format (see Output format sections of the manual for 'git diff-{asterisk}' commands) or diff-patch format. diffcore-break: For Splitting Up "Complete Rewrites" ---------------------------------------------------- The second transformation in the chain is diffcore-break, and is controlled by the -B option to the 'git diff-{asterisk}' commands. This is used to detect a filepair that represents "complete rewrite" and break such filepair into two filepairs that represent delete and create. E.g. If the input contained this filepair: ------------------------------------------------ :100644 100644 bcd1234... 0123456... M file0 ------------------------------------------------ and if it detects that the file "file0" is completely rewritten, it changes it to: ------------------------------------------------ :100644 000000 bcd1234... 0000000... D file0 :000000 100644 0000000... 0123456... A file0 ------------------------------------------------ For the purpose of breaking a filepair, diffcore-break examines the extent of changes between the contents of the files before and after modification (i.e. the contents that have "bcd1234..." and "0123456..." as the