5

Is there a way to make git commit to ignore line endings?

I managed to figure out how to make git diff to ignore line endings with

git diff --ignore-space-at-eol

This way I got diff to display only the lines I actually edited.

But the problem is that git diff by default considers my file as changed in whole, and then it commits the change accordingly.

Also I tried

git config --system core.autocrlf true

git config --system core.autocrlf false

None of these solved my problem!

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
cnom
  • 3,071
  • 4
  • 30
  • 60
  • If you're asking about trailing whitespace: I think the general advice is to avoid trailing whitespace. Remove it in the editor. You can set up a githook that refuses to commit if there is trailing whitespace. Also have a look at the following SO questions: http://stackoverflow.com/questions/19151940/git-remove-trailing-whitespace-in-new-files-before-commit , http://stackoverflow.com/questions/1583406/why-does-git-care-about-trailing-whitespace-in-my-files or http://stackoverflow.com/questions/591923/make-git-automatically-remove-trailing-whitespace-before-committing/19355398#19355398 . –  Nov 27 '14 at 12:26
  • No, Evert, I am asking about the control character for new line. I do avoid trailing whitespace. Yet, thank you for your comment. – cnom Nov 27 '14 at 12:46
  • Well, it's the second time I'm answering the same question today. Take a look at http://stackoverflow.com/questions/27155378/how-do-i-get-chef-cookbooks-to-be-downloaded-in-unix-format-on-windows/27168646#27168646 – user3159253 Nov 27 '14 at 12:48
  • The correct answer is to fix the files in the git index once, and then checkout them with a particular system specific line endings – user3159253 Nov 27 '14 at 12:50
  • There're more than one way to fix things in a particular repository, and which way is better depends on the status of the repository. – user3159253 Nov 27 '14 at 12:53
  • Have you tried setting `* text=auto` in .gitattributes file? Have a look at this: https://help.github.com/articles/dealing-with-line-endings/ – ZuoLi Nov 27 '14 at 12:58
  • Thanks ZuoLi, my local repository .gitattributes file has already * text=auto in the first line – cnom Nov 27 '14 at 13:34

1 Answers1

2

It seems that there is NO way to make git commit to ignore line endings by default!!

Just beware of Merging tools!

I figured out that my teams setting for line endings was perfectly OK, but the merging tool spoiled several files during merging a branch, and from then on we have the nightmare of EOL!! :)

cnom
  • 3,071
  • 4
  • 30
  • 60