I install latest git and configure it to highlight moved code:
$ git config diff.colormoved default
Here is how it looks when code is moved (see 1->2)
But 3-4 is not highlighted as moved code.
Here is standalone changes:
In the diff view there is a file tree showing all of the changes for that pull request. The colour of a particular file indicates the file change type: Green - ADDED (a new file was added) Blue - MODIFIED (an existing file was modified) Brown - COPIED (an existing file was copied to create a new file)
git diff --color-words git diff also has a special mode for highlighting changes with much better granularity: ‐‐color-words . This mode tokenizes added and removed lines by whitespace and then diffs those. Now the output displays only the color-coded words that have changed.
There is no output to git diff because Git doesn't see any changes inside your repository, only files outside the repository, which it considers 'untracked' and so ignores when generating a diff.
Diff command is used in git to track the difference between the changes made on a file. Since Git is a version control system, tracking changes are something very vital to it. Diff command takes two inputs and reflects the differences between them. It is not necessary that these inputs are files only.
See the documentation for --color-moved
/colormoved
in 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 tono
if the option is not given and tozebra
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.
specifically, that the default is zebra
and that it detects
Blocks of moved text of at least 20 alphanumeric characters
. my $ctx = shift;
doesn’t contain at least 20 alphanumeric characters. If you use git diff --color-moved=plain
, or add # ten more ANs
to the end of the line, your example will be highlighted as moved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With