Viewing diffs shows changed line endings on files whose line endings did not change

25 views
Skip to first unread message

James Larrowe

unread,
Jul 22, 2024, 5:39:22 AM (5 days ago) Jul 22
to git-for-windows
When changing a few lines in a file that already previously had CRLF line endings, the diff shows carriage returns being added at the end of the line. This results in a confusing situation where it appears that you are changing the line endings when in reality you are not.

When trying to remedy this problem, I converted the file to using LF-only line endings. This made the diff show the whole file being changed, which further confused me. After double-checking the original file in a hex editor, I discovered that it did indeed use CRLF line endings and that Git was erroneously showing the line endings being changed when they were not.

Examples:

Screenshot 2024-07-19 174102.png

Screenshot 2024-07-19 174321.png

Johannes Sixt

unread,
Jul 23, 2024, 3:49:43 AM (4 days ago) Jul 23
to James Larrowe, git-for-windows
Am 19.07.24 um 23:43 schrieb James Larrowe:
> When changing a few lines in a file that already previously had CRLF
> line endings, the diff shows carriage returns being added at the end of
> the line. This results in a confusing situation where it appears that
> you are changing the line endings when in reality you are not.

First check whether you have core.whitespace set:

git config core.whitespace

If not, set it to this:

git config core.whitespace trailing-space,space-before-tab,cr-at-eol

If you have it set already, change the setting to include cr-at-eol.
With this setting, the CR (^M) is not treated as trailing whitespace
anymore, but as part of the line terminator.

Please report back if this solved your problem.

-- Hannes

Reply all
Reply to author
Forward
0 new messages