Skip to main content

.gitattributes

基础使用

首先,在仓库的根目录下创建名为 .gitattributes 的文件。

*.js    eol=lf
*.jsx eol=lf
*.json eol=lf
*.json linguist-language=JSON-with-Comments

把该文件提交并推送到服务器上。

git add .
git commit -m "Added .gitattributes to repo"
git push

现在,任何人从仓库获取代码后,创建以及修改文件时,git 都会自动地设置好正确的文件结尾。

重置 GitAttributes

git rm --cached -r
git reset --hard

上面的命令就会根据文件 .gitattributes 中的定义,更新文件的结尾行。

任何变更都会自动使用指定文件的文件结尾行格式。

下一步,可以通知团队成员或者协作者去执行 Git 属性重置的命令。

现在,prettier 就不会在提示有关 CR 的问题了,所有的开发者都可以安心写代码了!