brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: git add with renormalize fixes line endings after a .gitattributes change

Git
~/tips/tip-git-add-renormalize-line-endings

git add .gitattributes

Re-applies your line ending rules to files that are already in the repository.

A new .gitattributes rule only affects files that git touches afterwards. Files committed with Windows line endings stay that way until you tell git to look at them again.

echo '* text=auto eol=lf' > .gitattributes
git add .gitattributes
git add --renormalize .
git commit -m "Normalize line endings"

--renormalize runs every tracked file through the clean filters and line ending rules again and stages the result. Files that were committed with CRLF line endings get staged as LF, and git status shows them as modified. The rule * text=auto eol=lf tells git to store text files with LF and check them out with LF too, while leaving binary files alone.

Check the result with git diff --cached --stat before committing. Expect a big commit if many files had CRLF, so I’d keep it separate from real changes. It’s also a good candidate for a .git-blame-ignore-revs file.

Your working tree may still have the old line endings after this. Git only changed what’s staged. Other people get the normalized files on their next pull, but their own uncommitted changes in those files will conflict with every line. Pick a quiet moment, and tell the others before you push.

Further reading: git-add documentation, gitattributes documentation

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link