问题描述
是否有办法在 .gitattributes 中执行 core.autocrlf = input 以传播政策在我的同事?
详细我想要的是转换为 lf 在添加
em>并在 checkout 上保留 。问题是, code> text 也不是 eol 做我想要的 .gitattributes code> eol 有3个可接受的值:
- lf c $ c
- lf
- crlf
- native
$ b
理想情况下,我希望我的 .gitattributes 文件看起来像像这样:
lockquote
* text eol = asis
Git不会转换在提交时,而是在 git add 上。 (更确切地说,它在将对象复制到存储库并生成散列值的操作上进行转换 - 但对于大多数情况而言,无论如何这只是 git add )。它应用了任何干净的过滤器,并执行输入侧的EOL操作。 (同样,当从存储库复制到工作树时出现输出端污迹过滤器和EOL操作,该工作树对于大多数用途为 git checkout 和 git reset --hard 。)
根据,设置 eol = lf :
因此,尽管我没有真正测试过它,但它听起来像 * eol = lf 就是你想要的。 请注意,这与 core.eol 不同,后者的行为与您在问题中描述的行为相同;这仅适用于 .gitattributes 设置,该设置适用于与名称模式匹配的文件。
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:
Ideally I would like my .gitattributes file to look like this:
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:
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.
这篇关于通过.gitattributes强制core.autocrlf =输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!