6

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.

MHebes
  • 951
  • 7
  • 19

2 Answers2

7

This option works for me:

WinMerge -> Edit -> Options -> Compare -> General: 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

Charlie
  • 521
  • 6
  • 16
  • This doesn't do it if you have one file with some blank lines inserted and the other one doesn't AND there are character-level differences between the non-blank lines. In that case, "Align similar lines" is needed. And these other options seem redundant to that one (except the line conversion probably). – Fizz May 30 '22 at 10:33
1

You could add a .gitattributes for your file. This would run a tool to normalize/beautify/prettify both files before comparison.

This will run .json files through json_pp before compare:

echo "*.json diff=json" >> .gitattributes
git config diff.json.textconv json_pp

Check out git documentation for details: https://git-scm.com/docs/gitattributes

Source: https://t-a-w.blogspot.com/2016/05/sensible-git-diff-for-json-files.html

JD Frias
  • 4,069
  • 3
  • 22
  • 22
  • This definitely does work to show semantic diffs, but I would still rather a winmerge-specific option that still shows the original files, but doesn't highlight the code style differences. Running a formatter can get a little slow for larger cpp files, and I'm also worried about the issues it could cause when editing diffs and saving them. I don't want to accidentally commit formatting changes if I don't need to. – MHebes Jul 10 '20 at 17:07
  • I use Beyond Compare has custom rules for comparison, and tons of other features. It is paid though, well wroth it in my opinion #notsponsored – JD Frias Jul 28 '20 at 21:32