What's git's heuristic for assigning content modifications to file paths?

前端 未结 2 1739
我寻月下人不归
我寻月下人不归 2020-11-29 11:07

Short version:

short of poring over git\'s source code, where can I find a full description of the heuristics that git uses

2条回答
  •  执笔经年
    2020-11-29 12:06

    ... short of poring over git's source code, where can I find a full description of the heuristics that git uses to associate chunks of content with specific tracked pathnames?

    Depending on what you mean by "full" I don't think you can find such a thing. (In particular, how are "percentages" calculated? Is it by lines, or characters/bytes, or something else? Does doing a word-oriented diff change things?) But the magic is all inside git diff, where it is computed dynamically every time a diff is to be shown; and the heuristics have several control knobs that give strong clues:

    --no-renames

    Turn off rename detection, even when the configuration file gives the default to do so.

    -B[][/], --break-rewrites[=[][/]]

    Break complete rewrite changes into pairs of delete and create. This serves two purposes:

    • It affects the way a change that amounts to a total rewrite of a file not as a series of deletion and insertion mixed together with a very few lines that happen to match textually as the context, but as a single deletion of everything old followed by a single insertion of everything new, and the number m controls this aspect of the -B option (defaults to 60%). -B/70% specifies that less than 30% of the original should remain in the result for Git to consider it a total rewrite (i.e. otherwise the resulting patch will be a series of deletion and insertion mixed together with context lines).

    • When used with -M, a totally-rewritten file is also considered as the source of a rename (usually -M only considers a file that disappeared as the source of a rename), and the number n controls this aspect of the -B option (defaults to 50%). -B20% specifies that a change with addition and deletion compared to 20% or more of the file's size are eligible for being picked up as a possible source of a rename to another file.

    and so on; see the documentation for git-diff.

提交回复
热议问题