用 .gitattributes 控制换行符

按文件类型规范化 CRLF/LF,让跨平台差异保持干净。

macOSGit命令行配置低风险
在 .gitattributes 中加入 *.sh text eol=lf,强制 shell 脚本使用 LF。

01命令

命令
$ git config core.autocrlf input  # plus .gitattributes

02作用说明

换行符漂移会造成噪声差异甚至脚本失效;提交 .gitattributes 后规则对所有克隆一致生效,而本地的 core.autocrlf 因机器而异。这是把配置当作代码。

03风险

风险低风险
使用条件Git 2.20+ (install with Homebrew or Xcode Command Line Tools)
系统兼容性macOS with Git installed (Homebrew or Xcode Command Line Tools)
!注意: 修改换行规则可能产生一次性大差异;转换仓库前请与团队协调。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

最后验证: 2026-10-13 · 分类: 开发者