Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions github/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ Repositories under the W3C organization may represent the work of Working Groups

[Backup of GitHub organizations](backup.md)
: How W3C keeps a backup of the different GitHub organizations.

[The "spurious EOL normalization" bug](spurious_eol.md)
: What to do when a PR suddenly changes all lines in a file?
72 changes: 72 additions & 0 deletions github/spurious_eol.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
GIT --
title: The "spurious EOL normalization" bug
toc: false
---


# Description of the bug

After
[applying suggested changes](https://docs.github.com/en/pull-requests/how-tos/review-pull-requests/incorporating-feedback-in-your-pull-request#applying-suggested-changes)
in a PR, and possibly after using the
[online editor](https://docs.github.com/en/codespaces/the-githubdev-web-based-editor),
the PR appears to modify *all the lines* of a given file.

@TallTed TallTed Aug 29, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
the PR appears to modify *all the lines* of a given file.
GitHub forces the PR to modify *all the lines* of a given file,
"normalizing" the EOL characters to CRLF.
GitHub claims they do this only
when they have detected a mix of EOL characters in the file.
To the best of my knowledge, they have not documented what problem is caused by such
a mix of EOL characters, nor why they are defaulting to
normalize to Windows CRLF, which appears
to be a change from previous default behavior.

The change in most line is in fact only touching the end-of-line (EOL) character, changing all LFs to CRLFs.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The change in most line is in fact only touching the end-of-line (EOL) character, changing all LFs to CRLFs.
The change in most lines is in fact only touching the end-of-line (EOL) character, changing all LFs to CRLFs.


## What causes the bug

It seems that the bug appears when the following conditions are met:

* the file contains a mix of CRLF and LF, and
* changes are commited to the file by
[applying suggested changes](https://docs.github.com/en/pull-requests/how-tos/review-pull-requests/incorporating-feedback-in-your-pull-request#applying-suggested-changes)
or (TBC) using the
[online editor](https://docs.github.com/en/codespaces/the-githubdev-web-based-editor).

> [!Note]
> This behaviour is not a "normal" GIT behaviour:
> to reproduce it, one has to tweak the GIT configuration between the time the file is checked out and the time the file is commited!
> It seems more likely that it is a GitHUb bug.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I was able to repro this bug entirely in git by setting autocrlf=false on my Windows client and checking out files from a repo that did not have a .gitattributes file specifying end-of-line behavior.



# Dealing with it

* It is possible to ask GIT or github to ignore whitespaces when showing the difference between two versions of a file:

+ in github, by clicking on the cog-wheel button in the 'Files changed' view of the PR,
and checking 'Hide whitespace' (alternatively: adds the `?w=1` parameter to the URL,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
and checking 'Hide whitespace' (alternatively: adds the `?w=1` parameter to the URL,
and checking 'Hide whitespace' (alternatively: add the `?w=1` parameter to the URL,

[example](https://github.com/pchampin/test_eol_bug/pull/2/changes?w=1))

+ on the command line, using the `--ignore-all-space` option of `git diff`

Comment thread
pchampin marked this conversation as resolved.
> [!Note]
> Note that this does not *fix* anything; it only changes what is displayed as "changed lines". Further, it conceals changes in indentation which may increase or decrease the number of space characters used for indents, as well as changing indent characters between tabs and spaces. These remain to be manually fixed after resolving the EOL issue.

* Advanced users may "fix" the PR by

+ checkout the branch of the PR locally
+ modify the incriminated commit with [`git rebase -i`](https://git-scm.com/docs/git-rebase#_interactive_mode);
a useful command to change all CRLFs back to LFs is `sed 's/\r$//' -i [filename]`
+ "force-push" the rebased branch with `git push --force`
Comment on lines +47 to +50

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a slightly more verbose description of what can/should be done is worth adding for less advanced users...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why I marked this item as for "advanced users" :-)
I didn't have time to turn this into a proper tutorial, and I don't think this should block this page from being added. But +1 to be more explicit about it, eventually.


This will retain the individual commits with their authors and messages.

# Preventing it from happening again

A workaround consists in:

* adding a
[`.gitattributes`](https://git-scm.com/docs/gitattributes)
file in the root folder of the repository, containing the following line:
```
* text=auto
```
Comment on lines +61 to +63

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Others were advocating

* text=auto eol=lf

are we 100% sure that the eol=lf is superfluous? Or is it wrong to set it this way?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that eol=lf will force the local copies to use LF, including on Windows, which some (crude) editors may not like.

From the GIT documentation

If the eol attribute is unspecified for a file, its line endings in the working directory are determined by the core.autocrlf or core.eol configuration variable (see the definitions of those options in git-config[1]). If text is set but neither of those variables is, the default is eol=crlf on Windows and eol=lf on all other platforms.

So leaving it unspecified seems better.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I did explicitly test this on Windows, and it does force all files in my working directory to have LF line endings, which is wrong for Windows. That said, even Notepad can handle such files, so I am not sure what practical impact it has these days. But I advocate for not forcing that (no eol=lf added) as it seems unrelated (you just want to normalize line endings in the repo, what I do with the files should be up to me).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that eol=lf will force the local copies to use LF, including on Windows

Maybe so. Somewhere someone must be able to answer why when those configuration files are not in place, a Mac-based LF user of the GitHub browser interface gets their file(s) normalized to the Windows CRLF.


This instructs GIT to guess which files are text files;
any new file deemed to be text will be kept *in the repository*
with EOLs normalized to LF,
regardless of the EOLs in the local copies.

* optionally running `git add . --renormalize` followed by `git commit -m "normalize all EOL"`
to ask GIT to remove all mixed EOL in text files already present in the repository.
(Again, this will *not* change the local copies.)