AI code review: stop CRLF churn before sending the diff

gitcode-reviewworkflowcontext-budget

TL;DR: Diagnose line-ending churn locally before sending a large patch to an AI reviewer. Compare ordinary and end-of-line-insensitive diffs, then inspect repository attributes and staged bytes. Normalize only approved paths in a separate change; whitespace filters are a diagnostic view, not evidence that the full patch is safe.

What you’ll be able to do:

  • Distinguish a line-ending rewrite from a logical edit.
  • Check the index and working tree without changing global Git settings.
  • Prepare a smaller review packet while preserving the full original evidence.

Honest take: Spend local inspection effort before paying for another model pass over a formatting accident.

Why can a tiny AI edit produce a whole-file diff?

A file can keep the same visible text while changing its line endings from CRLF to LF, or the reverse. An editor, formatter, code generator, or agent-driven rewrite can cause this; the diff alone does not identify which program did it. Git’s text attributes and configuration determine how those bytes are normalized when added or checked out.

The Git attributes manual, checked November 9, 2026, documents the text and eol attributes. Before blaming the coding model for rewriting everything, inspect what changed at the byte boundary. Sending the entire patch back with “please make a smaller change” can repeat the same edit cycle without correcting the editor or repository policy.

This workflow uses ordinary local Git commands. It requires an existing Git installation and a scratch repository for the optional reproduction, with no GPU, paid API, hosted agent, or new subscription. It is a review-input budgeting method, not a benchmark of any coding product. We measured the fixture’s diff counts, not model tokens, latency, acceptance rate, or money saved.

What should you record before changing anything?

Record repository status, the ordinary diff, and staged changes before normalization. An index can already contain unrelated work; git add --renormalize is a staging operation, not a read-only display setting.

git status --short
git diff --stat
git diff --cached --stat
git diff --numstat -- src/settings.txt
git diff --cached --numstat -- src/settings.txt

Replace src/settings.txt with a real path you intend to inspect. Keep the -- separator, especially when passing paths through scripts. The diff manual describes the cached and working-tree comparisons. Do not interpret a clean working-tree diff as proof that the index contains nothing.

Save patches only in a private location if you need an audit trail. Source diffs may contain secrets, customer data, or uncommitted credentials. A local evidence folder is not automatically suitable for upload to an AI service. Include only reviewed files in an external review packet, according to your project’s data policy.

If you have both staged and unstaged edits, first decide which snapshot the reviewer should evaluate. The existing staged-diff review guide explains that boundary. Line-ending diagnosis does not remove the need to identify the snapshot.

How do you distinguish CRLF churn from a substantive change?

Compare the ordinary diff with a view that ignores whitespace changes at line ends. Use this as a clue, then inspect the full patch and file type before deciding that the difference is harmless.

git diff -- src/settings.txt
git diff --ignore-space-at-eol -- src/settings.txt
git diff --check -- src/settings.txt

The Git diff documentation defines --ignore-space-at-eol. It can hide trailing spaces as well as line-ending differences, so a disappearing diff does not uniquely diagnose CRLF. For formats where trailing spaces matter, that filtered view can hide a real behavior change. Avoid casually substituting -w, which ignores a broader class of whitespace differences.

ViewUseful questionBoundary
Ordinary diffWhat changes will a reviewer see?A line-ending rewrite can dominate it
--ignore-space-at-eolDoes the difference remain without end-of-line whitespace?May hide meaningful trailing spaces
--checkDoes Git report whitespace errors?Does not prove semantic equivalence
Cached diffWhat bytes are currently proposed for commit?Does not include every unstaged edit

Do not use the filtered patch as the only acceptance artifact. Python indentation, Markdown line breaks, test fixtures, generated golden files, and byte-sensitive protocols all deserve special attention. A reviewer needs enough context to understand whether whitespace is part of the contract.

Which Git settings explain the result?

Inspect the effective attributes, the recorded line endings, and relevant configuration. These commands are read-only:

git ls-files --eol -- src/settings.txt
git check-attr text eol -- src/settings.txt
git config --show-origin --get core.autocrlf
git config --show-origin --get core.eol

The ls-files manual documents the i/ index and w/ working-tree fields. A line such as i/lf w/crlf can be a normal checkout arrangement rather than a bug. Read the attribute portion of the same output and the project policy before changing it.

The check-attr command shows the attributes that apply to the path. Configuration inspection with --show-origin helps identify where a setting came from, as documented in git config. An unset --get query can return a nonzero status; that does not mean the repository is damaged. Automation should distinguish “not configured” from an execution failure.

Do not “fix” a shared repository by changing core.autocrlf globally. That changes behavior in other repositories and does not explain the bytes already staged here. Prefer an explicit, reviewed repository policy when a policy change is actually needed.

What did the local reproduction show?

On November 9, 2026, a throwaway repository reproduced the problem using Git with core.autocrlf=false. The starting file contained four CRLF-terminated lines:

alpha=1
beta=2
gamma=3
delta=4

The visible block does not express its line-ending bytes. The fixture wrote them explicitly in Python, committed that file, then rewrote it with LF bytes while keeping all four values unchanged. Ordinary git diff --numstat returned:

4       4       config.txt

The end-of-line-insensitive diff with --exit-code returned zero for that pure line-ending change. After changing beta=2 to beta=9, the same filtered comparison returned one, identifying a remaining difference. These exit codes were checked in the local fixture; they were not inferred from a model’s description of the patch.

Next, the fixture introduced a scoped text policy, staged normalization, reviewed it, and committed that normalization inside the disposable repository. A subsequent change to the one value produced:

1       1       config.txt

The raw counts are additions and deletions, not a measured token ratio. A production file’s review cost also depends on context, prompts, provider metering, caching, and how much of the file an agent resends. Report “smaller input” unless you have actual billing evidence for a dollar claim.

How should you normalize an approved file?

Normalize approved paths only after separating real edits from formatting work. If the working tree contains valuable user changes, preserve that state and agree on the normalization scope before staging anything.

For a repository that intentionally wants LF for these text files, a reviewed .gitattributes rule might be:

*.txt text eol=lf

That pattern is an example policy, not a universal recommendation for every .txt file. Narrow it to a directory or individual path if your repository includes byte-sensitive samples. Do not apply a broad text rule to binary assets or fixtures that intentionally preserve CRLF.

After approving the rule and confirming the selected file has no unrelated edits:

git add -- .gitattributes
git add --renormalize -- src/settings.txt
git diff --cached --stat
git diff --cached -- src/settings.txt
git diff --cached --ignore-space-at-eol -- src/settings.txt
git diff --cached --check

The add manual documents renormalization. It reapplies the clean process to tracked files and places results in the index. The explicit path bounds that operation. A repository-wide git add --renormalize . has a much larger review surface and can stage unrelated tracked modifications; do not use it reflexively in a dirty project.

Commit normalization separately from the feature when your workflow permits it. A clean separation lets reviewers inspect the policy and formatting decision once, then review the behavioral change on its own. If the normalization includes unexpected content changes, stop and reconcile them instead of discarding the working tree.

What should you send to the AI reviewer afterward?

Send the actual intended snapshot, with the normalization boundary explained. Do not quietly remove portions of the commit merely because a filtered view is shorter.

A useful handoff says which base revision the patch uses, whether the patch includes staged or working-tree changes, which normalization was reviewed separately, and which tests ran against the final code. If the branch has multiple commits, the merge-base review packet guide helps establish the correct comparison base.

Use the full logical patch after normalization, relevant surrounding source, and an acceptance command. If a reviewer needs to evaluate the normalization itself, include the original evidence and attribute change as a separate artifact. Avoid feeding both versions without explanation: the model may reason about the wrong snapshot or suggest reintroducing the old policy.

Set a local retry boundary. When the same whole-file churn returns, inspect the editor or formatter setting responsible before requesting another paid review. That is a process recommendation, not evidence that a particular vendor charges for every retry or that a fixed number of retries is optimal.

Honest take: When should you leave the line endings alone?

Leave line endings unchanged when they are intentional, required by a format, or outside the current task’s approved scope. A noisy diff can be inconvenient without being incorrect. Preserve generated files according to the generator’s contract rather than repeatedly editing the output by hand.

For a mixed patch with both formatting and logical changes, prioritize preserving the real work. Use a separate branch or scratch copy to investigate normalization if necessary. Do not use a reset or repository-wide restore to make the status display look clean.

The default recommendation is narrow: establish the snapshot, diagnose the whitespace boundary, approve the policy, and review the final bytes. Spend model attention on behavior after the repository can express that behavior clearly.

Sources

Last updated November 9, 2026. Results come from a disposable local Git fixture; no paid coding agent, token benchmark, or savings measurement was used.

Was this article helpful?

Know which coding tool is worth paying for

Hands-on comparisons of AI coding assistants and what each one costs to run — including the local-model path. Sent only when something changes. Unsubscribe anytime.