之前都是一个人用github做项目,环境,OS都是不变的,没遇到什么奇怪问题。现在小团队使用github, 有的成员用Mac, 有的用Windows, 就会出现换行符不一致的问题。详细参考 http://blog.jobbole.com/46200/
我们的处理方法是,在repo中加入.gitattributes文件,参考https://help.github.com/articles/dealing-with-line-endings 和 http://krablekod.ru/content/git-ignore-file-ending-crlf-problem
文件.gitattributes:
# Set default behaviour, in case users don't have core.autocrlf set.
* text=auto
# Explicitly declare text files we want to always be normalized and converted
# to native line endings on checkout.
*.c text
*.h text
*.java text
# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf
# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
text=auto 的作用是,git会一直自动把指定类型的文件push的时候使用Unix 换行符,pull的时候使用当前系统的换行符。
各系统换行符:
win:“ ”,0x0D0A;
linux:“ ”,0x0A;
mac:" ",0x0D;