Skip to content

Improve diff word highlighting #11517

@gerhardol

Description

@gerhardol

Feature description

This is related to #11464, the word-diff part is probably dependent on that change that requires support for ansi escapes for terminal colors.
However, the discussion on what type of improvement that is reasonable is separate.

--

Git Extensions has a basic algorithm to show changed blocks of changes in a patch.
https://github.com/gitextensions/gitextensions/blob/master/GitUI/Editor/Diff/DiffHighlightService.cs#L105
This is useful, but if there are more changes on a line it is insufficient
image

git-diff do not show word diff by default, only patches with added/deleted lines.
It is however possible ro enable word-diff, similar to to GH.
https://git-scm.com/docs/git-diff#Documentation/git-diff.txt-color
However, the changes is no longer presented as a patch

image

git-diff word-diff also has a "porcelain" format, but that is not possible to use to recreate a patch format.
The reason is that added/removed empty lines is not marked and that initial whitespace on new/deleted lines are presented as context. (You can guess with a high probability.)
This example can be presented correctly
(This is how I want to present the changes, you see changes very quickly).

image

Other tools have tried to overcome the Git word-diff limitation.
The diff-highlight script is in the Git repo and post process the output (some more than GE built in).
This includes https://github.com/so-fancy/diff-so-fancy (adding to diff-highlight)
Some examples in Delta
https://dandavison.github.io/delta/comparisons-with-other-tools.html
GitHub has an improved algorithm that show changes word by word::

image

--

Several ways forward to improve the GE diff:

If patch format is not changed, other diff presentations could be provided even if they are not presented as patches, so you can toggle the presentation

Environment

  • Git Extensions 33.33.33
  • Build 2555afe6d7461476cb01320cca0023231e4f28cb
  • Git 2.43.0.windows.1
  • Microsoft Windows NT 10.0.19045.0
  • .NET 8.0.1
  • DPI 96dpi (no scaling)
  • Portable: False
  • Microsoft.WindowsDesktop.App Versions
    Microsoft.WindowsDesktop.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 7.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 8.0.0-rc.2.23479.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 8.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions