Is there a way to enforce core.autocrlf=input
from within the .gitattributes
in order to propagate the policy throughout my colleagues?
In detail what I want is to convert to lf
on add and leave as is
on checkout.
The problem is that neither text
nor eol
do what I want in .gitattributes
since eol
has 3 acceptable values:
lf
crlf
native
Ideally I would like my .gitattributes
file to look like this:
* text eol=asis
In detail what I want is to convert to lf on commit and leave as is on checkout.
Git doesn't convert on commit, but rather on git add
. (More precisely, it does conversions on operations that copy the object into the repository and produce a hash value—but for most purposes, that's just git add
anyway.) At this time it applies any "clean" filters and does input-side EOL operations. (Likewise, output-side "smudge" filters and EOL operations occur when copying out from the repository to the work-tree, which for most purposes is git checkout
and git reset --hard
.)
According to the gitattributes documentation, setting eol=lf
:
... forces Git to normalize line endings to LF on checkin and prevents conversion to CRLF when the file is checked out.
Hence, though I have not actually tested this, it sounds like * eol=lf
is just what you want. Note that this is different from core.eol
, which behaves as you described in your question; this is only for a .gitattributes
setting, which applies to the files that match the name-pattern.
来源:https://stackoverflow.com/questions/42667996/enforce-core-autocrlf-input-through-gitattributes