I have been bitten by the Windows/Linux line-ending issue with git. It seems, via GitHub, MSysGit, and other sources, that the best solution is to have your local repos set
My procedure for dealing with the line endings is as follows (battle tested on many repos):
When creating a new repo:
.gitattributes
in the very first commit along with other typical files as .gitignore
and README.md
When dealing with an existing repo:
.gitattributes
accordinglygit commit -a -m "Modified gitattributes"
git rm --cached -r . && git reset --hard && git commit -a -m 'Normalize CRLF' -n"
-n
(--no-verify
is to skip pre-commit hooks)alias fixCRLF="..."
In .gitattributes
I declare all text files explicitly as having LF EOL since generally Windows tooling is compatible with LF while non-Windows tooling is not compatible with CRLF (even many nodejs command line tools assume LF and hence can change the EOL in your files).
.gitattributes
My .gitattributes
usually looks like:
*.html eol=lf
*.js eol=lf
*.json eol=lf
*.less eol=lf
*.md eol=lf
*.svg eol=lf
*.xml eol=lf
To figure out what distinct extensions are tracked by git in the current repo, look here
Once this is done, there's one more common caveat though.
Say your master
is already up-to-date and normalized, and then you checkout outdated-branch
. Quite often right after checking out that branch, git marks many files as modified.
The solution is to do a fake commit (git add -A . && git commit -m 'fake commit'
) and then git rebase master
. After the rebase, the fake commit should go away.