Tmux
Summary: Author: 张亚飞 | Read Time: 2 minute read | Published: 2016-04-25
Filed under
—
Categories:
Linux
—
Tags:
Note,
CRLF-LF
如何判断文件是哪种换行符
检查所有包含 CRLF 换行符的文件
$ egrep -l $'\r'\$ *
AndroidPushMQTT.md
AndroidStudio.md
CoamApp.md
DebugAndroidLog.md
DebugAndroidStethoAppWithChrome.md
EventBus.md
LearnAndroidContext.md
LearnAndroidDesign.md
LearnAndroidFragment.md
LearnAndroidUnitTest.md
LearnListView.md
LearnOther.md
find . -type f -exec file {} \; | grep “CRLF” | awk -F ‘:’ ‘{ print $1 }’
$ find . -type f -exec file {} \;
./DebugAndroidLog.md: UTF-8 Unicode text, with CRLF line terminators
./LearnListView.md: UTF-8 Unicode text, with CRLF line terminators
./LearnAndroidDesign.md: exported SGML document text, UTF-8 Unicode text, with CRLF line terminators
./LearnAndroidContext.md: UTF-8 Unicode text, with CRLF line terminators
./EventBus.md: UTF-8 Unicode text, with CRLF line terminators
./Realm.md: UTF-8 Unicode text
./LearnAndroidUnitTest.md: exported SGML document text, UTF-8 Unicode text, with CRLF line terminators
./AndroidPushMQTT.md: UTF-8 Unicode text, with CRLF line terminators
./LearnOther.md: UTF-8 Unicode text, with CRLF line terminators
./AndroidNote.md: UTF-8 Unicode text
./LearnGradle.md: UTF-8 Unicode text
./AndroidStudio.md: UTF-8 Unicode text, with CRLF line terminators
./Retrofit.md: UTF-8 Unicode text
./AndroidNDK.md: exported SGML document text, UTF-8 Unicode text
./CoamApp.md: exported SGML document text, UTF-8 Unicode text, with CRLF line terminators
./DebugAndroidStethoAppWithChrome.md: UTF-8 Unicode text, with CRLF line terminators
./ProGuard.md: c program text, UTF-8 Unicode text
./LearnAndroidFragment.md: UTF-8 Unicode text, with CRLF line terminators
CRLF
转换成LF
brew install dos2unix
find . -type f -print0 | xargs -0 dos2unix
IDE 设置使用 CRLF - 不起作用(备用)
在 Windows 下要配置 LF 作为换行符首先要设置 core.autocrlf 为 false:
git config --global core.autocrlf false
在项目的 .gitattributes
下为所有文件设置 text=auto ,表示新文件的行尾自动转换.如果是文本文件,则在文件入Git库时,行尾自动转换为LF:
* text=auto
并且全局设置 core.eol 为 lf:
git config --global core.eol lf
也可以在单独项目分别配置例外:
git config core.eol crlf
配置完后,你想把Git项目下所有的旧文件都应用此设置自动转换. 进入项目根目录下并执行:
git rm --cached -rf .
git diff --cached --name-only -z | xargs -n 50 -0 git add -f
- How to Ensure Always LF not CRLF on Windows
- How do I force git to use LF instead of CR+LF under windows?
.gitattributes
的几种配置
* text=auto
*.txt text
*.jpg -text
*.vcproj text eol=crlf
*.sh text eol=lf
*.py eol=lf
说明:
第1行,对任何文件,设置text=auto,表示文件的行尾自动转换.如果是文本文件,则在文件入Git库时,行尾自动转换为LF.如果已经在入Git库中的文件的行尾为CRLF,则该文件在入Git库时,不再转换为LF. 第2行,对于txt文件,标记为文本文件,并进行行尾规范化. 第3行,对于jpg文件,标记为非文本文件,不进行任何的行尾转换. 第4行,对于vcproj文件,标记为文本文件,在文件入Git库时进行规范化,即行尾为LF.但是在检出到工作目录时,行尾自动转换为CRLF. 第5行,对于sh文件,标记为文本文件,在文件入Git库时进行规范化,即行尾为LF.在检出到工作目录时,行尾也不会转换为CRLF(即保持LF). 第6行,对于py文件,只针对工作目录中的文件,行尾为LF.
Comments