git arbitrarily picks line-ending settings

42 Views Asked by At

git config core.autocrlf returns true and my repository contains a .gitattributes that contains * text=auto.

However, I have noticed that some files are stored with LF line-endings as expected, and others not. The files I store as CRLF might come back as LF once a colleague has touched it. The colleague has core.autocrlf set to input.

So I edited two of these mystery files and then committed them.

Locally I have this:

Name               Length
----               ------
ResultCursor.cs     17643
UserSession.cs      19171

git ls-tree -r -l HEAD returns:

100644 blob d5ade9bb1426af4b37a3332f5d4cc4cde7150f8c   17115    ResultCursor.cs
100644 blob 25d531c00d085e4735baa2ba07c84d0507284f24   19171    UserSession.cs

I.e. ResultCursor.cs shrunk as expected, but UserSession.cs was stored as-is. Note: Same folder. Same extension. UTF8, no BOM.

git diff works fine with both files (so neither should be perceived as binary). How can I force both files to respect autocrlf settings when committing changes?

git version 2.27.0.windows.1

0

There are 0 best solutions below