While setting up Git for a project, I've noticed that the line-ending normalization works a bit different on Linux and on Windows.
As I understand the Git documentation on this subject, the behavior on Windows is the correct one. Specifically, when a .gitattributes
file is present, it should override the core.autocrlf
setting.
The following table shows the results of some experimentation I've done. The two left-most columns shows the .gitattributes
file and the core.autocrlf
setting. The other columns shows the result of the following git
commands:
git rm --cached <file>
(force next checkout to perform line normalization handling).git checkout HEAD -- <file>
(checkout the file, applying line ending normalization)git ls-files --eol <file>
(check the line endings in the working tree)
+----------------+---------------+-------------+--------------+--------------+--------------------------+--------------------------+ | .gitattributes | core.autocrlf | Linux 2.7.2 | Linux 2.11.0 | Linux 2.16.2 | Windows 2.12.2.windows.2 | Windows 2.16.1.windows.1 | | | | | | | | | +----------------+---------------+-------------+--------------+--------------+--------------------------+--------------------------+ | None | true | w/crlf | w/crlf | w/crlf | w/crlf | w/crlf | | | | | | | | | +----------------+---------------+-------------+--------------+--------------+--------------------------+--------------------------+ | None | false | w/lf | w/lf | w/lf | w/lf | w/lf | | | | | | | | | +----------------+---------------+-------------+--------------+--------------+--------------------------+--------------------------+ | * text=auto | true | w/crlf | w/crlf | w/crlf | w/crlf | w/crlf | | | | | | | | | +----------------+---------------+-------------+--------------+--------------+--------------------------+--------------------------+ | * text=auto | false | w/lf | w/lf | w/lf | w/crlf | w/crlf | | | | | | | | | +----------------+---------------+-------------+--------------+--------------+--------------------------+--------------------------+ | * text=auto | true | w/crlf | w/crlf | w/crlf | w/crlf | w/crlf | | test text | | | | | | | | | | | | | | | +----------------+---------------+-------------+--------------+--------------+--------------------------+--------------------------+ | * text=auto | false | w/lf | w/lf | w/lf | w/crlf | w/crlf | | test text | | | | | | | | | | | | | | | +----------------+---------------+-------------+--------------+--------------+--------------------------+--------------------------+
As you can see, on Linux, it seems that the core.autocrlf
settings has effect, even when a .gitattributes
file is present.
I'd like some help to determine whether this is actually a bug.
Note: the .gitattributes documentation has been updated with Git 2.21 (Feb. 2019)
See commit c9446f0, commit 2b68085 (29 Jan 2019) by Jeff King (
peff
).Helped-by: Torsten Bögershausen (
tboegi
).(Merged by Junio C Hamano --
gitster
-- in commit 13e2630, 07 Feb 2019)And that refers back to Mark Adelsberger's answer regarding
core.eol
config.But this has changed with Git 2.21:
It seems the misunderstanding comes from interpreting the text attribute as meaning the same thing as the autocrlf config setting.
From the
gitattributes
docs (https://git-scm.com/docs/gitattributes):(Emphasis added.)
So if you want to use attributes to control the line ending you get in the work tree, you need to set the eol attribute (not merely the text attributes).
In fact there are a couple attributes and a couple config options involved in how line endings are handled, and there are differences (by design) in the default behavior between Windows and *nix. From the
git config
docs (https://git-scm.com/docs/git-config):So, to answer your question: no, what you've described is not a bug.