Ian Warburton
Ian Warburton

Reputation: 15676

Why does GitHub think my code has differences?

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.

Upvotes: 0

Views: 394

Answers (1)

John Szakmeister
John Szakmeister

Reputation: 47032

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"

Upvotes: 2

Related Questions