通过.gitattributes强制core.autocrlf =输入 [英] Enforce core.autocrlf=input through .gitattributes

查看:535
本文介绍了通过.gitattributes强制core.autocrlf =输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有办法在 .gitattributes 中执行 core.autocrlf = input 以传播政策在我的同事?

详细我想要的是转换为 lf 添加

em>并在 checkout 上保留



问题是, code> text 也不是 eol 做我想要的 .gitattributes code> eol 有3个可接受的值:


  1. lf 本地
  2. c $ c

    $ b

    理想情况下,我希望我的 .gitattributes 文件看起来像像这样:

    lockquote

    * text eol = asis



    解决方案


    详细我想要的是在提交时转换为lf并保持原样结账。


    Git不会转换在提交时,而是在 git add 上。 (更确切地说,它在将对象复制到存储库并生成散列值的操作上进行转换 - 但对于大多数情况而言,无论如何这只是 git add )。它应用了任何干净的过滤器,并执行输入侧的EOL操作。 (同样,当从存储库复制到工作树时出现输出端污迹过滤器和EOL操作,该工作树对于大多数用途为 git checkout git reset --hard 。)



    根据 gitattributes文档,设置 eol = lf


    ...强制Git将行结束标准化为
    上的LF,并在文件
    检出时阻止转换为CRLF 。

    因此,尽管我没有真正测试过它,但它听起来像 * 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:

    1. lf
    2. crlf
    3. 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.

    这篇关于通过.gitattributes强制core.autocrlf =输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆