https://stackoverflow.com/questions/1967370/git-replacing-lf-with-crlf
https://help.github.com/articles/dealing-with-line-endings/
# view current setting
# system wide %ProgramFiles(x86)%\git\etc\gitconfig
# per user ~/.gitconfig
# per repo .git/config
git config core.autocrlf
# set
# add autocrlf=false to system-wide gitconfig # per-system solution
git config --global core.autocrlf false # per-user solution
git config --local core.autocrlf false # per-project solution
# Configure Git on OS X to properly handle line endings
git config --global core.autocrlf input
core.autocrlf=true: core.autocrlf=input: core.autocrlf=false:
repo repo repo
^ V ^ V ^ V
/ \ / \ / \
crlf->lf lf->crlf crlf->lf \ / \
/ \ / \ / \
If you're working on Windows
- use
true, if to use the project under Unix as well, and you don't want to configure IDE to use Unix line ending. - use
false, if to use the project under Windows only - NEVER use
input, unless you have a good reason
git configsettings can be overridden bygitattributessettings.crlf -> lfconversion only happens when adding new files, crlf files already existing in the repo aren't affected.
# 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.
*.bat text eol=crlf
# all text files detected by Git will use lf
* text eol=lf
# Denote all files that are truly binary and should not be modified.
*.jar binary
*.png binary
*.gif binary
*.ico binary
The best way is to first backup your files with Git, delete every file in your repository (except the .git directory), and then restore the files all at once.
git add . -u
git commit -m "save before refresh line endings"
# force Git to rescan the working directory
rm .git/index
# rewrite index to pick up all the new line ending
git reset
# show the rewritten,normalised files
git status
# add all your changed files back, and prepare a commit
# This is your chance to inspect which files were unchanged.
git add -u
# A lot of "warning: CRLF will be replaced by LF in file."
# rewrite .gitattributes
git ad .gitattributes
git commit -m "normalise all the line endings"