问题
I do development on Mac OS X. I have a user who is contributing code with CRLF line endings. He currently does not use git. I create a branch, then switch my working tree to it. I copy his file into the working tree. When I try to stage the file, I receive the error fatal: CRLF would be replaced by LF in pcb-gcode.ulp.
I've been through endless posts and tried suggestions (such as .gitattributes & git reset) and the only solution seems to be to use sfk
or similar to change the line endings when I get the file from him.
Is there a way to have git change his CRLF line ends to LF when staging and committing, and use LF if I checkout the branch to my working tree? It seems that there would be an option to have git just recognize a line ending as a line ending and give me what is appropriate for my OS when I check it out.
git config --global -l (excerpt)
core.autocrlf=input
core.safecrlf=true
git config --local -l
(nothing relevant)
I'm using SourceTree and the remote repo is hosted on Assembla, in case that is pertinent.
回答1:
I think, you can try new (1.7.2+) core.eol
Sets the line ending type to use in the working directory for files that have the text property set. Alternatives are 'lf', 'crlf' and 'native', which uses the platform's native line ending. The default value is native
And don't use buggy and not-obvious core.autocrlf
来源:https://stackoverflow.com/questions/21355458/git-line-ends-redux-mac-os-git-with-contributions-for-windows-user