How to ignore moved lines in a diff

diff()

I am currently working on a source code generation tool. To make sure that my changes do no introduce any new bugs, a diff between the output of the program before and after my changes would theoretically be a valuable tool.

However, this turns out to be harder than one might think, because the tool outputs lines where the order does not matter (like import statements, function declarations, …) in a semi-randomly ordered way. Because of this, the output of diff is cluttered with many changes that are in fact only lines moved to another position in the same file.

Is there a way to make diff ignore these moves and only output the lines that have really been added or removed?

Best Answer

You could do a simple diff, store the result somewhere (to avoid another diff), loop through the lines in either version, then remove those from the other side.

This spawned a separate project for the working code. The code.