Enforce core.autocrlf=input through .gitattributes

孤街醉人 提交于 2019-12-09 11:20:27

问题


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:

  1. lf
  2. crlf
  3. native

Ideally I would like my .gitattributes file to look like this:

* text eol=asis


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!