0

When I add...

# Auto detect text files and perform LF normalization
* text=auto

...to my config file then the GitHub app/client says that many (if not all?) of the files in the repository have changed. For many of them it says that the entire file has changed even though it obviously hasn't. Obviously this is an issue with line endings but I don't understand why this is happeneing.

It seems that as soon as you tell Git (via the config file) that a file type is text then it throws up differences.

Ian Warburton
  • 15,170
  • 23
  • 107
  • 189

1 Answers1

2

With text=auto, Git wants to store the files in LF format--it doesn't simply apply a filter to what is there. As a result, any file that isn't already stored with LF endings will show up as being modified. You probably want to follow the advice on the gitattributes man page in the eol conversion section and do:

$ rm .git/index     # Remove the index to force Git to
$ git reset         # re-scan the working directory
$ git status        # Show files that will be normalized
$ git add -u
$ git add .gitattributes
$ git commit -m "Introduce end-of-line normalization"
John Szakmeister
  • 44,691
  • 9
  • 89
  • 79
  • I thought it was something like that. Thanks. – Ian Warburton Apr 18 '13 at 13:22
  • Trouble is that every file looks like its been completely changed after that commit. I think the files in the repository might have all been in Windows format. – Ian Warburton Apr 18 '13 at 13:32
  • Yeah, I really dislike how it works. I have a template that I use for creating new repositories to make sure line endings are normalized from the start to avoid this kind of problem. FWIW, Subversion and others have similar issues. – John Szakmeister Apr 18 '13 at 17:51
  • I got a clean commit after setting 'core.autocrlf = false'. So its now leaving the new-line encoding as is. – Ian Warburton Apr 19 '13 at 08:18
  • I need to sit down and look at `core.autocrlf` more... I've turned it off on my Windows VM as well. It's supposed to alleviate problems, but I feel like it introduces more. Glad you've got things working better for you! – John Szakmeister Apr 19 '13 at 08:23
  • I found this article helpful... http://timclem.wordpress.com/2012/03/01/mind-the-end-of-your-line/ . I also so wrote a blog post (not sure how accurate it is!)... http://ianwarburton.wordpress.com – Ian Warburton Apr 19 '13 at 09:34