Reputation: 59
One of our developers' text editor messes up the line endings of our PHP files. We've tried all settings, but the editor still seems to replace the CR-LF's with LF's on saving.
Of course, the most sane thing to do is replace the editor with a decent one, but I though: why not configure Git for handling the differences in line ending? Here's where I get stuck; I can't get it to work properly and I'd like your advice.
It seems the files we check out have CR-LF line endings. When our developer edits them and stores them, they same to have LF endings. When committing the file, not only do the lines change, but every line is removed and inserted again.
I've set core.autocrlf
to true
. When committing, I get a warning that all LF will be replaced by CR-LF. The file will have the original endings in your work directory. But still, all lines are removed and added again. When merging with another branch, this gives conflicts.
I tried making a .gitattributes
file with *.php text
. Same result as with core.autocrlf
.
So my question is: is there a way to configure Git to only commit the changes our programmer's made and leave alone the lines where only the line ending has changed?
Upvotes: 5
Views: 3522
Reputation: 5269
From what I remember of the documentation, you can't do precisely that.
However, the configuration let you ignore specific line endings.
If you want to store in the repository all files using LF line endings, run:
git config --system core.autocrlf false
git config --system core.eol lf
Also you may want to ensure that the global, system and local configs are set to what you are trying to achieve:
git config --global -l
git config --system -l
git config --local -l
Upvotes: 2