避免在Windows中使用的git仓库复制到Linux下出现^M换行,导致git status的时候曝红色
可以执行如下操作
说明:在git仓库中新建一个.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.
*.c text
*.h text
# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf
*.css text eol=crlf
*.js text eol=crlf
*.md text eol=crlf
*.txt text eol=crlf
*.sql text eol=crlf
*.php text eol=crlf
*.cpp text eol=crlf
*.cxx text eol=crlf
# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
- 其中text eol=crlf表示使用CRLF换行,看自己需要屏蔽的哪种类型的文件夹,可自行更改。
- 根据Ubuntu上哪些类型的文件被标红, 便在.gitattributes上将text属性设置为eol=crlf。
- 查看一下状态:git status,发现.gitattributes修改未暂存
- 暂存:git add .gitattributes
- 提交:git commit -m “Add a .gitattributes file”
- 接下来上传到Ubuntu上,.gitattributes就发挥了作用,使用git status查看,整个工作区都清静了。
2、Git仓库忽略文件和文件夹权限问题
- git config --global core.fileMode false
3、warning: CRLF will be replaced by LF in XXX .
- git config core.autocrlf false