Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git 换行符 #50

techial1042 opened this Issue Feb 22, 2019 · 1 comment


None yet
1 participant
Copy link

techial1042 commented Feb 22, 2019

Git 换行符

操作系统 换行符
Unix 和 OS X \n ,0x0A(LF)
Windows \r\n,0x0D0A(CRLF)
早期 Mac OS \r,0x0D(CR)

在 Git 中可以使用 AutoCRLFSafeCRLF 对换行符进行设置。


# 拒绝提交包含混合换行符的文件
git config --global core.safecrlf true

# 提交时转换为LF,检出时不转换
git config --global core.autocrlf input

在多人团队协作中,我们可以使用添加 .gitattributes 文件来限定换行符。这个文件通常放在项目的根目录,也就是有 .git 文件夹的那个目录。

.gitattributes 每一行格式如下

要匹配的文件模式 属性1 属性2 ...


# 对于任意文件,当该文件的格式为 text,即文本时,在提交的时候,行尾自动转换成 lf。
* text eol=lf



This comment has been minimized.

Copy link
Owner Author

techial1042 commented Feb 22, 2019


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.