I’m having an issue with line endings in a repo I’m working on. The repo was originally created on a Mac and all files in it use LF only for line endings. I have
core.autocrlf set to
false, so no attributes are being applied to the files.
When I clone the repo on another Mac, all files have LF as the line ending. When I clone on Windows, however, some files have CRLF line endings.
git rev-parse HEAD:foo to get the hash of the file, then used
git cat-file -p "abc123...abc" | xxd to view the file in hex. This shows LF as the line ending, confirming that the file should only ever have had LF.
git status in Windows shows that there are no changes to
foo, even though it has CRLF endings. Converting the line endings in
foo from CRLF to just LF then shows that
git status does detect the change.
When I run
git status in WSL on Windows, it shows all the files with errant CRs as being changed. Running
git status in Git Bash on Windows gives the same results as running it in Windows.
What is causing this issue? How do I make git stop changing my line endings?
The issue you are facing is related to Git’s automatic line ending conversion. Git tries to automatically convert line endings based on the
To make Git stop changing your line endings, you can follow these steps:
input by running the following command:
git config --global core.autocrlf input
This setting tells Git to convert CRLF line endings to LF on commit but not the other way around.
lf by running the following command:
git config --global core.eol lf
This setting tells Git to normalize line endings to LF when checking out files.
Ensure that any existing files with CRLF line endings are converted to LF line endings. You can do this using the following command:
git rm --cached -r .
git reset --hard
Be cautious as this will remove all files from the index and reset your repository to the latest commit. Make sure to commit any changes you want to keep before running these commands.
After completing these steps, Git should stop changing your line endings, and you should have consistent LF line endings in your repository across different platforms.