用 .gitattributes 控制换行符
按文件类型规范化 CRLF/LF,让跨平台差异保持干净。
在 .gitattributes 中加入 *.sh text eol=lf,强制 shell 脚本使用 LF。
01命令
命令
$ git config core.autocrlf input # plus .gitattributes02作用说明
换行符漂移会造成噪声差异甚至脚本失效;提交 .gitattributes 后规则对所有克隆一致生效,而本地的 core.autocrlf 因机器而异。这是把配置当作代码。
03风险
!注意: 修改换行规则可能产生一次性大差异;转换仓库前请与团队协调。
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- git-gitattributes documentation依据: Documents .gitattributes, including the text and eol attributes.
最后验证: 2026-10-13 · 分类: 开发者