Results.

SCEPTRA.TECH

Git Shows Changes Across the Whole File? Inspect Line Endings Before Converting Anything

Original line-ending diagram distinguishing the index, working copy and effective attributes

Your editor says you changed one sentence, but Git's diff appears to replace most of the file. Before accepting a huge patch or changing a global setting, check whether the file's line endings changed. Git can store text one way in its index and use another line-ending style in your working copy.

I would diagnose one tracked file first. The commands below inspect information; they do not convert files, stage changes or change configuration. Run them from the repository root and replace the example path with your actual tracked file.

Compare the index with the working copy

git ls-files --eol -- "docs/setup.txt"

Git documents three useful parts of this output: i/ describes the content in the index, w/ describes the working-tree file, and attr/ shows the line-ending attribute setting used for the path. The index is the staging area, so it is not necessarily identical to the last commit if you already staged changes.

An illustrative result might look like this:

i/lf    w/crlf    attr/text eol=crlf    docs/setup.txt

That is not automatically a problem. It says the index uses LF while the working copy uses CRLF, with an attribute asking for CRLF in the working tree. A difference between i/ and w/ alone does not prove your patch is wrong.

The command can also report mixed. That is a useful clue to investigate rather than an instruction to convert the whole repository. If nothing is listed, check the path and whether the file is tracked before drawing a conclusion about its contents.

Ask which attributes actually apply

git check-attr text eol -- "docs/setup.txt"

This reports the effective values for the named attributes. A value can be set, unset, unspecified, or a string such as auto, lf or crlf, depending on the attribute. In particular, unspecified is not the same as an instruction to use LF.

Git's attribute rules explain why reading only the root .gitattributes file can be misleading. A file nearer the path can take precedence, and local .git/info/attributes has higher precedence still. Global and system attribute files can also participate. The command helps establish the result without guessing from one visible file.

Understand the policy before changing it

The text attribute controls end-of-line conversion. With text normalization enabled, Git can normalize line endings to LF in the index while checkout behavior determines the working-copy style. The eol attribute specifies a working-tree line-ending style for checkout. Configuration and platform defaults can matter when attributes leave the choice open.

That is why a blanket recommendation to turn a global setting on or off is a poor first fix. It can change behavior in other repositories without explaining the current file. A project shared by Windows, macOS and Linux contributors should have an agreed policy, not a different emergency workaround on every laptop.

Keep normalization separate from the real edit

Once the evidence points to an accidental editor conversion, preserve your actual edits before making any repair. Check the editor's current line-ending setting against the project's intended policy. Do not discard the file to make the diff disappear if it contains work you need.

If the project intentionally needs a normalization change, treat that as a separate reviewed task. Git's documentation describes renormalizing from a clean working directory, inspecting what will change and handling files that should not be normalized. That is different from running a repository-wide staging command in the middle of unrelated work.

My stopping point for this check is a clear explanation of the file's index style, working-copy style and effective attributes. Then review the actual patch under the project's policy. These commands diagnose line endings; they do not prove that every changed line is harmless or replace a code review.

Sources

Comments