-
Notifications
You must be signed in to change notification settings - Fork 68
add documentation about the 'spurious EOL normalization' bug in GitHub #452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. | ||||||
| The change in most line is in fact only touching the end-of-line (EOL) character, changing all LFs to CRLFs. | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| ## 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. | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| [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` | ||||||
|
|
||||||
|
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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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...
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's why I marked this item as for "advanced users" :-) |
||||||
|
|
||||||
| 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Others were advocating are we 100% sure that the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My understanding is that From the GIT documentation
So leaving it unspecified seems better. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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).
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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.) | ||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.