Use this skill when git keeps changing files unexpectedly on commit, files show changes even though nothing was edited, or when dealing with CRLF/LF line ending issues across platforms. Provides diagnosis and fixes for git line ending configuration problems.
Symptoms this fixes:
Root cause: Windows uses CRLF (\r\n), Unix/Mac uses LF (\n). Git can auto-convert but wrong settings cause thrashing.
Two main options:
core.autocrlf=true - Git converts LF→CRLF on checkout, CRLF→LF on commitcore.autocrlf=false - No conversion, .gitattributes controls normalizationWhen to use each: → Decision Guide
Quick fix workflow: → Fix Line Ending Issues
Configuration:
Troubleshooting:
Platform-Specific:
git config core.autocrlf
Returns: true, false, or input (or nothing if unset)
core.autocrlf=true (Windows standard).gitattributes.gitattributes if presentgit config core.autocrlf true
core.autocrlf=false + .gitattributes (Recommended).gitattributes.gitattributes controls everythinggit config core.autocrlf false
Verification:
git config core.autocrlf
# Should show: false
.gitattributes (Recommended)# Set autocrlf to false
git config core.autocrlf false
# Create .gitattributes if missing
.gitattributes example:
# Auto-detect text files, normalize to LF in repo
* text=auto
# Force LF for specific types
*.js text eol=lf
*.ts text eol=lf
*.json text eol=lf
*.md text eol=lf
*.yml text eol=lf
# Binary files
*.png binary
*.jpg binary
*.pdf binary
.gitattributesgit config core.autocrlf true
git config core.autocrlf input
# Or false if using .gitattributes
# Check current autocrlf setting
git config core.autocrlf
# Check if .gitattributes exists
ls .gitattributes # Unix/Mac
dir .gitattributes # Windows/PowerShell
# View what git sees as changed
git status --short
# See if it's line endings (will show no actual content changes)
git diff <filename>
Common conflict: core.autocrlf=true + .gitattributes with * text=auto
This causes git to convert twice, leading to thrashing.
# If you have .gitattributes, use:
git config core.autocrlf false
# If no .gitattributes and Windows-only team, use:
git config core.autocrlf true
After changing settings, normalize all files:
# Save any work first!
git add . -u
git commit -m "Checkpoint before line ending normalization"
# Remove all files from git index
git rm --cached -r .
# Re-add all files (applies new line ending rules)
git add .
# Check what changed
git status
# Commit the normalization
git commit -m "Normalize line endings"
# Make sure everything is committed
git status
# Re-checkout with new settings
git rm --cached -r .
git reset --hard
Check for mixed settings:
# Check global config
git config --global core.autocrlf
# Check local config (overrides global)
git config --local core.autocrlf
# Check if .gitattributes is being ignored
cat .gitattributes
Solution: Make sure local and global settings align:
# Set globally
git config --global core.autocrlf false
# Set for this repo
git config --local core.autocrlf false
Check VS Code settings:
files.eol to \n (LF) or autoMake sure EOL is consistent:
// .vscode/settings.json
{
"files.eol": "\n"
}
This is transitional. After files stabilize with the new settings, the warnings stop.
To silence warnings during transition:
git config core.safecrlf warn # or false to completely disable
Fix: Mark them as binary in .gitattributes:
*.png binary
*.jpg binary
*.exe binary
*.dll binary
*.so binary
# Check current setting
git config core.autocrlf
# Recommended: Use false + .gitattributes
git config core.autocrlf false
# Check for .gitattributes
Test-Path .gitattributes
# Check current setting
git config core.autocrlf
# Recommended: Use input or false
git config core.autocrlf input # Converts CRLF→LF on commit only
# or
git config core.autocrlf false # No conversion, .gitattributes controls
VS Code typically uses LF (\n) by default. To match git settings:
Option 1: Configure VS Code to use LF
// .vscode/settings.json
{
"files.eol": "\n",
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true
}
Option 2: Let EditorConfig handle it
# .editorconfig
root = true
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
[*.{cmd,bat}]
end_of_line = crlf
# Create a test file with CRLF
echo "line1\r\nline2" > test.txt
# Add and check what git does
git add test.txt
# View what git stored (should be LF if normalized)
git show :test.txt | od -c # Unix/Mac
git show :test.txt | Format-Hex # PowerShell
# Clean up
git rm --cached test.txt
rm test.txt
| Setting | Windows→Repo | Repo→Windows | When to Use |
|---|---|---|---|
true | CRLF→LF | LF→CRLF | Windows-only, no .gitattributes |
false | No change | No change | With .gitattributes (cross-platform) |
input | CRLF→LF | No change | Mac/Linux only |