Skip to content

Instantly share code, notes, and snippets.

@phamngsinh
Created July 16, 2016 07:25
Show Gist options
  • Select an option

  • Save phamngsinh/0d69433f2adbee7511bf530d45b124c4 to your computer and use it in GitHub Desktop.

Select an option

Save phamngsinh/0d69433f2adbee7511bf530d45b124c4 to your computer and use it in GitHub Desktop.
What's the best CRLF,EOL in git
Two alternative strategies to get consistent about line-endings in mixed environments (Microsoft + Linux + Mac):
A. Global per All Repositories Setup
1) Convert all to one format
find . -type f -not -path "./.git/*" -exec dos2unix {} \;
git commit -a -m 'dos2unix conversion'
2) Set core.autocrlf to input on Linux/UNIX or true on MS Windowns (repository or global)
git config --global core.autocrlf input
3) [ Optional ] set core.safecrlf to true (to stop) or warn (to sing:) to add extra guard comparing if the reversed newline transformation would result in the same file
git config --global core.safecrlf true
B. Or per Repository Setup
1) Convert all to one format
find . -type f -not -path "./.git/*" -exec dos2unix {} \;
git commit -a -m 'dos2unix conversion'
2) add .gitattributes file to your repository
echo "* text=auto" > .gitattributes
git add .gitattributes
git commit -m 'adding .gitattributes for unified line-ending'
Don't worry about your binary files - Git should be smart enough about them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment