Last active
December 4, 2023 03:32
-
-
Save yuxi-liu-wired/64424f9c1aa47964f9edb8a8354ed3ad to your computer and use it in GitHub Desktop.
Run this in your local Git repo to convert it from CRLF to LF ending, and make sure it *stay so*.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
git config --global core.eol lf | |
git config --global core.autocrlf input | |
echo "* text=auto eol=lf" > .gitattributes | |
# Find files but exclude .git directory | |
find . -type f ! -path '*/.git/*' | while read -r file; do | |
# Check if the file is a text file | |
if file "$file" | grep -q text; then | |
sed -i 's/\r$//' "$file" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instructions
chmod +x crlf_to_lf.sh
./crlf_to_lf.sh
.How it works
.gitattributes
file in the repository, enforcing the use of LF line endings for all text files.