0

if you change this file:

div
    {
        max-width: 50%;
        max-height: 50%;
    }

into this:

div
    {
        max-width: 100%;
    }

git diff --word-diff will print:

div
    {
        max-width: [-50%;-]
[-      max-height: 50%;-]{+100%;+}
    }

wdiff:

div
    {
        max-width: [-50%;-]
[-      max-height: 50%;-] {+100%;+}
    }

this is confusing / unreadable

yes, diff correctly shows the easiest way of getting resulting one line from original 2 lines, but change becomes non-semantic

what i want is:

div
    {
        max-width: [-50%-]{+100%+};
[-      max-height: 50%;-] 
    }

i.e. 1) line 2 changed; 2) line 3 removed

of course, diff doesn't know the semantics, but we do know that in vast majority of source code all partial modifications of lines are individual per line, even if they are tied together

so i want to tell diff to regard every line separately when showing the changes

option --avoid-wraps of wdiff does not achieve this

option --word-diff-regex of git diff won't help either - it tells git what to treat as a word - i.e. an atomic thing that it should not try to modify to change into a different word in the other file - but it does not stop git from grouping added/removed words together - representing them as a single change, including when they are on different lines - i.e. have a newline character between them

is there a way to force any of these programs to always show changes on different lines separately, or is there a diff program that has such an option?

1
  • 1
    "Word diff" is by definition based on words. There are no lines. You want a line diff that highlights changed words. Git can't do that out of the box. Commented Nov 12 at 7:08

1 Answer 1

1

Install Difftastic and set this as default diff tool.

For installation instructions, see Installation in the manual.

https://difftastic.wilfred.me.uk/

git config --global diff.external difft

So whenever a git diff operation is performed ,instead of using git's built in diff engine this will use external diff tool named difft

Then use the

git diff

Difftastic is a CLI diff tool that compares files based on syntax, not line-by-line, using tree-sitter to parse code and produce accurate diffs.Using this for each comparison, this will highlight the logical differences.

Sign up to request clarification or add additional context in comments.

2 Comments

hello, Mariya. thanks, i tried difftastic - it doesn't solve the problem - it's very basic, doesn't give any options to control the comparison, shows partially wrong output in --display=inline mode, often doesn't understand word-by-word changes - interpreting them as full line changes instead, and its machine-readable json mode is declared as an unstable feature
have you used difftastic yourself?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.