gpt4 book ai didi

git - 为什么移动的代码在 git diff 中没有着色?

转载 作者:太空狗 更新时间:2023-10-29 12:58:58 25 4
gpt4 key购买 nike

我安装了最新的 git 并将其配置为突出显示移动的代码:

$ git config diff.colormoved default

这是移动代码后的样子(参见 1->2) enter image description here

但是 3-4 没有突出显示为移动代码。

这里是独立的变化:

enter image description here

最佳答案

请参阅 --color-moved 的文档/colormoved在 git-diff(1) 中:

--color-moved[=<mode>]

Moved lines of code are colored differently. It can be changed by the diff.colorMoved configuration setting. The <mode> defaults to no if the option is not given and to zebra if the option with no mode is given. The mode must be one of:

  • no
    Moved lines are not highlighted.

  • default
    Is a synonym for zebra. This may change to a more sensible mode in the future.

  • plain
    Any line that is added in one location and was removed in another location will be colored with color.diff.newMoved. Similarly color.diff.oldMoved will be used for removed lines that are added somewhere else in the diff. This mode picks up any moved line, but it is not very useful in a review to determine if a block of code was moved without permutation.

  • zebra
    Blocks of moved text of at least 20 alphanumeric characters are detected greedily. The detected blocks are painted using either the color.diff.{old,new}Moved color or color.diff.{old,new}MovedAlternative. The change between the two colors indicates that a new block was detected.

  • dimmed_zebra
    Similar to zebra, but additional dimming of uninteresting parts of moved code is performed. The bordering lines of two adjacent blocks are considered interesting, the rest is uninteresting.

具体来说,默认值为 zebra并且它检测到

Blocks of moved text of at least 20 alphanumeric characters

. my $ctx = shift;不包含至少 20 个字母数字字符。如果你使用 git diff --color-moved=plain , 或添加 # ten more ANs到行尾,您的示例将突出显示为已移动。

关于git - 为什么移动的代码在 git diff 中没有着色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48165922/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com