THE GITHTML FIELD GUIDE

Diagnose a Git diff that marks every line changed

When Git marks nearly every line changed, inspect line endings, encoding, whitespace, and formatter activity before assuming the file was rewritten intentionally. Compare a whitespace-tolerant diff with the normal patch and inspect effective attributes. Preserve the original content, then separate any deliberate normalization from functional changes so reviewers can see both accurately.

Find a discriminating comparison

An editor can convert LF to CRLF, change indentation, remove trailing spaces, or rewrite encoding when saving. Those changes can make a tiny logical edit appear enormous. Begin with one representative file and compare the ordinary patch with a view that ignores the suspected whitespace difference. A smaller tolerant diff is a clue, not proof that every hidden change is harmless.

Whitespace can be meaningful in some formats and languages, so do not approve a patch solely because an ignore-all-space view looks small. Encoding changes can also alter bytes without being a simple line-ending issue. Inspect the tool that saved the file and its project settings before changing Git configuration.

Inspect attributes and stored line endings

The commands below are read-only. ls-files --eol reports information about index and working-tree line endings, while check-attr reveals policy for the selected path. Use the exact affected filename. Compare both normal and tolerant output so the review does not accidentally hide meaningful changes.

  1. Check whether a formatter or editor changed many files on save. Pause the broad operation before attempting a repository-wide repair.
  2. Inspect repository attributes and local conversion settings together; changing a global preference can affect unrelated projects and may conflict with the intended shared policy.
shell
git diff --stat -- path/to/file
git diff -- path/to/file
git diff --ignore-space-at-eol -- path/to/file
git ls-files --eol -- path/to/file
git check-attr text eol -- path/to/file

Repair narrowly and review the real edit

If the conversion was accidental, preserve the intended logical edit and use a controlled editor or file conversion process to restore the agreed representation. Do not discard the whole file without keeping the actual work. If normalization is intentional, put it in a clearly described mechanical change separate from behavior edits when practical.

Afterward, inspect the normal diff again and run the relevant checks. The desired result is not merely a smaller patch: it is the correct bytes, correct behavior, and a reviewable explanation. Record the editor or attribute setting that caused the churn so it does not recur the next time a teammate saves the file.

  1. If ls-files --eol reports different index and working-tree endings, compare that evidence with the repository’s text and eol attributes. A conversion can be intentional at checkout time. Do not normalize the committed file merely because its local representation differs; first identify which layer produced the noisy patch.
  2. For an indentation-sensitive file, compare a representative nested block before and after the save. A whitespace-insensitive diff can hide a changed relationship between statements. Keep the normal patch available during review and run the format’s own parser or tests after preserving the intended logical edit.

Sources and further reading

AI-assisted writing with source-linked guidance and illustrative examples. Read our editorial approach or report a correction.

All fixing git problems guides →

Read as MarkdownAll guides

Diagnose a Git diff that marks every line changed · gitHtml