0 Preface/Foreword
Git版本管控工具功能强大,在使用过程中,在多人合作的项目开发过程中,经常会遇到提交代码时出现的warning提醒,尤其是换行符。
Linux/Unix/Mac OS操作系统的换行符使用LF符号(\n),而Windows使用CR(\r)LF(\n)作为换行符。
CR:Carriage Return,回车,ASCII码0x0D
LF:Line Feed,换行,ASCII码0x0A
1 Usage
使用方法可参考文章:Configuring Git to handle line endings - GitHub Docs
[转载]通过阅读 git-config 文档理解 Git 如何使用autocrlf、safecrlf、eol和.gitattributes处理line-ending - 简书
1.1 Warning
warning: LF will be replaced by CRLF in xxx file
The file will have its origninal line endings in your working directory.
1.2 添加gitattributes文件
# Set the default behavior, in case people don't have core.autocrlf set. * text=auto# Explicitly declare text files you want to always be normalized and converted # to native line endings on checkout. #*.uvoptx text #*.uvprojx text# Declare files that will always have CRLF line endings on checkout *.uvoptx text eol=lf *.uvprojx text eol=lf
1.3 常用template file
# Help git with file types
* text=auto
*.o binary
*.obj binary
*.bin binary
*.lib binary
*.mbn binary
*.svf binary# Always use LF EOL on shell script files, otherwise Docker cannot run scripts
# in a folder mapped from Windows into the Docker container.
*.sh eol=lf# Documentation files are often changed in multiple concurrent branches.
# Use git union strategy when merging, so it keeps both side's modifications
# without conflicts.
README.md merge=union
CHANGELOG.md merge=union
RELEASENOTES.md merge=union