Video in progress

Strong Junior 🌿 Git

When developers on Windows and macOS work in one repository, whole files show up as "changed" although nothing actually changed. What is the cause?

Line endings: Windows uses CRLF (\r\n), while Linux/macOS use LF (\n). Git counts every line as changed. The fix is to set a rule at the repository level with .gitattributes.

📖 Answer

The symptom: every line in the diff is red and green, but there is no visible difference. Or a shell script fails in Docker with bad interpreter: /bin/bash^M.

Relying on everyone's core.autocrlf setting is not reliable, since someone will forget to set it. The reliable way is to put a .gitattributes in the repository:

* text=auto eol=lf
*.bat text eol=crlf
*.jar binary
*.png binary

This tells Git: text files should be LF in the repository and on checkout, only .bat stays in Windows format, and binary files are not touched at all.

Normalize the existing files once:

git add --renormalize .
git commit -m "Qator oxirlari LF'ga keltirildi"

This commit looks big, so make it separately, with no other changes.