Guide

Diff Precision and Ignore Strategies

How to choose word or character precision and apply ignore rules that make a comparison meaningful without changing the compared text.

A useful diff removes the differences you do not care about and keeps the ones you do. Precision controls how a changed line is highlighted; ignore rules control which differences count at all.

01Choosing precision

  • Start with a smart mode that chooses word precision when the changed pair shares a meaningful token and character precision otherwise.
  • Use word precision when whole identifiers or words changed.
  • Use character precision for small edits inside a long token, such as a changed digit.

02Ignore rules

  • Whitespace, case, and line-ending rules make those differences compare equal.
  • A literal or regular-expression rule removes a matching pattern, such as a timestamp or build id, from the comparison key.
  • Rules apply to the comparison key only; the retained text and any exported file are never rewritten.

Frequently asked questions

Do ignore rules modify my files?
No. They change only which differences are matched; the editors and every exported file keep the bytes you supplied.
When should I use character precision instead of word precision?
Use character precision for a small edit inside one long token, such as a changed digit or letter, where word-level highlighting would mark the whole token.

Sources

  1. GNU diffutils manual — Free Software Foundation
  2. POSIX diff utility — The Open Group
  3. An O(ND) Difference Algorithm and Its Variations (Myers, 1986) — ACM