Enforce core.autocrlf=input through .gitattributes

前端 未结 3 2055
梦毁少年i
梦毁少年i 2021-02-14 10:42

Is there a way to enforce core.autocrlf=input from within the .gitattributes in order to propagate the policy throughout my colleagues?

In deta

3条回答
  •  北恋
    北恋 (楼主)
    2021-02-14 11:37

    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.

提交回复
热议问题