【问题标题】:Using gitattributes to replace repository line endings使用 gitattributes 替换存储库行结尾
【发布时间】:2017-03-01 16:09:18
【问题描述】:

我试图在包含 windows 和 unix 特定文件的共享存储库中规范化行尾,但我无法让它按照我期望的方式工作。

我们都在 Windows 机器上开发,但要求行尾(取决于文件类型)为 LF 或 CRLF。已建议开发人员将 autocrlf 设置为 false,以便不会在存储库中更改某些需要 CRLF 存在的文件(存在 windows 和 unix 文件格式的混合),并在必要时手动更改行尾。

有人建议使用 gitattributes 可以在一定程度上减轻监管应该使用哪些文件结尾的需要,但我一直无法做到这一点。

这些是我的用户 git 设置:

[core]
    eol = native
    bare = false
    filemode = false
    hideDotFiles = dotGitOnly
    ignorecase = true
    repositoryformatversion = 0
    symlinks = false
    autocrlf = true
    editor = 'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -nosession -noPlugin

programdata git 设置:

[core]
    fscache = true

仓库 git 设置:

[core]
    logallrefupdates = true

.git 属性文件:

# convert all to lf
* text eol=lf

# convert these to windows line endings
*.sbm   text eol=crlf
*.sbp   text eol=crlf
*.sin   text eol=crlf
*.bat   text eol=crlf
*.cmd   text eol=crlf
*.ini   text eol=crlf
*.inf   text eol=crlf
/strataclient/BubbleHelp/* text eol=crlf

# don't touch binary files
*.dot   binary
*.dll   binary
*.exe   binary
*.ocx   binary
*.lic   binary
*.cfn   binary

为了测试它,我创建了一个包含 .gitattributes 文件的小提交(我一直在修改它以测试不同的组合),然后运行以下命令:

git rm --cached -r .
git reset --hard

它似乎改变了一些行尾,但不是我所期望的那样。

我尝试遵循各种指南,但似乎没有一个能够做出预期的影响深远的变化。我希望所有文本文件都更改为 LF(例如 java、properties、txt),除非它是 CRLF 列出的类型之一(例如 cmd、bat)。

【问题讨论】:

    标签: git


    【解决方案1】:

    我偶然发现了这个问题,我很好奇这在 2 年后是否仍然是一个问题?

    随便!在最近的 Git 版本中,您可以在提交 .gitattributes 文件后执行 git add --renormalize,如下所述:Configuring Git to handle line endings

    【讨论】:

      猜你喜欢
      • 2014-03-16
      • 1970-01-01
      • 2015-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多