Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinMerge - ignore all whitespace including newlines and formatting changes

Tags:

git

winmerge

How can I ignore "code style" changes while using WinMerge as a difftool? Specifically across two commits.

So that

thing
{
  a,
  b
}

and

thing { a, b }

would be treated as identical.

Essentially this question, but for winmerge rather than diff.

.gitconfig:

[diff]
    tool = winmerge
[difftool]
    prompt = false
[difftool "winmerge"]
    cmd = "$HOME/scripts/winmerge.sh" "$LOCAL" "$REMOTE"
[mergetool]
    prompt = false
    keepBackup = false
    keepTemporaries = false
[merge]
    tool = winmerge
[mergetool "winmerge"]
    cmd = "'C:/Program Files (x86)/WinMerge/WinMergeU.exe'" -e -u -fm -dl \"Local\" -dr \"Remote\" "$LOCAL" "$MERGED" "$REMOTE"

(winmerge.sh just calls WinMergeU.exe -e -u -wr "$1" "$2")

None of the command line options seem to fit, and I think line filters won't work because they are per-line.

like image 732
MHebes Avatar asked Nov 16 '25 03:11

MHebes


2 Answers

These options work for me:

WinMerge -> Edit -> Options -> Compare -> General ->

  • -> Whitespaces -> Ignore all;
  • -> Ignore blank lines;
  • -> Ignore carriage return differences (Windows/Unix/Mac)
  • etc.

The answer was taken from https://superuser.com/questions/174275/can-i-compare-only-file-contents

like image 80
Charlie Avatar answered Nov 18 '25 16:11

Charlie


To answer my own question with the benefit of more time:

  • This is not possible with WinMerge
  • difftastic does this for read-only diffs at the cost of speed and memory
  • No tool that I'm aware of does writable diffs (e.g. conflict resolution) while showing semantic-based diffs

Not-quite-there solutions:

Ignore blank lines; Ignore carriage return differences (Windows/Unix/Mac)

This ignores line feed differences, and full blank line differences, but does not compare files semantically. It does help in certain simple cases.

Line filter ^\s*$

Same as "Ignore blank lines"

.gitattributes formatter with textconv for specific file types

This is the closest option for read-only diffs, with the downsides of:

  • needing to define a separate attribute (and formatter) for each file type
  • displaying the formatted versions of the files rather than the original

My current solution

  • For conflict resolution, use WinMerge as-is with as much of the "ignore" options turned on as possible. Resolving conflicts with formatting changes is a massive pain no matter what you do, so try to isolate formatting changes to their own merges.
  • For diff viewing, use difftastic which uses tree-sitter to compare code on an AST level rather than a textual level
  • When difftastic is slow or hogging memory, fall back to diff/WinMerge/VSCode
like image 33
MHebes Avatar answered Nov 18 '25 15:11

MHebes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!