Skip to content

Instantly share code, notes, and snippets.

@phamngsinh
Created July 13, 2016 07:19
Show Gist options
  • Select an option

  • Save phamngsinh/4a5cceeff252e5888c87b4a840cb1bc0 to your computer and use it in GitHub Desktop.

Select an option

Save phamngsinh/4a5cceeff252e5888c87b4a840cb1bc0 to your computer and use it in GitHub Desktop.
LF instead of CR+LF under OS in git
28
down vote
I come back to this answer fairly often, though none of these are quite right for me. That said, the right answer for me is a mixture of the others.
What I find works is the following:
git config --global core.eol lf
git config --global core.autocrlf input
For repos that were checked out after those global settings were set, everything will be checked out as whatever it is in the repo – hopefully LF (\n). Any CRLF will be converted to just LF on checkin.
With an existing repo that you have already checked out – that has the correct line endings in the repo but not your working copy – you can run the following commands to fix it:
git rm -rf --cached .
git reset --hard HEAD
This will delete (rm) recursively (r) without prompt (-f), all files except those that you have edited (--cached), from the current directory (.). The reset then returns all of those files to a state where they have their true line endings (matching what's in the repo).
If you need to fix the line endings of files in a repo, I recommend grabbing an editor that will let you do that in bulk like IntelliJ or Sublime Text, but I'm sure any good one will likely support this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment