I'm regularly using the gnu-utils patch and diff. Using git, I often do:
git diff
Often simple changes create a large patch because the only that changed was, for example, adding a if/else loop and everything inside is indented to the right.
Reviewing such a patch can be cumbersome because only line by line manual comparison can indicate if anything has essentially changed within the indented code. We may be speaking about a few lines of code only, or about dozens (or much more) of nested code. (I know: such an hypothetically large function would better be split into smaller functions, but that's beside the point).
Can't GNU diff/patch be aware when the only change within a code block is the indentation and let the developer know as much?
Are there any other diff tools that operate this way?
Edit: Ok, there is --ignore-space-change
but then we are in a either/or situation: either we have a human-more-readable patch or we have a complete patch that the machine would know how to read. Can't we have the best of both world with a more elaborate diff tool that would show to the human space changes for what they are while allowing the machine to apply the patch fully?
This research was published in a 1976 paper co-written with James W. Hunt, who developed an initial prototype of diff. The algorithm this paper described became known as the Hunt–Szymanski algorithm.
When referring to text, indent or indentation is the increase or decrease of space between the left and right margin of a paragraph. To indent text, move the cursor to the front of the line and press the Tab on the keyboard. Example of indented text.
With GNU diff you can pass -b
or --ignore-space-change
to ignore changes in the amount of white space in a patch.
If you use emacs and have been sent a patch, you can also use M-x diff-ignore-whitespace-hunk
to reformat the patch to ignore white space in a particular hunk. Or diff-refine-hunk
to highlight changes at a character by character level, which tends to point out the "meat" of a change.
As for applying patches, you can use the -l
or --ignore-whitespace
with GNU patch to ignore tabs and spaces changes. Just be careful with Python code :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With