How can I get Git to truly *ignore* line endings?

Ryan Lundy picture Ryan Lundy · Mar 19, 2014 · Viewed 9.6k times · Source

How can I tell Git to truly not care about line endings? To leave them as LF or CRLF, as they originally were, and check them in the same way?

I'm using a Git repository with git-tf to check in to a TFS repository. The rest of my team is using TFS exclusively.

That being the case, sometimes they change line endings without knowing it. For instance, recently a third-party tool normalized its line endings, among other changes. Our repo was updated with these changes, and now the files show as having changes in my directory due to different line endings.

What I really want, for this particular repository, is to have Git pretend line-ending changes don't exist. If it's LF, leave it as LF. If it's CRLF, leave it as CRLF.

What setting or combination of settings do I need in order to do this?

Answer

rvdginste picture rvdginste · Jun 3, 2015

For future reference: the most stable way to implement this, is using a .gitattributes file that is committed in the root of the git repository.

This file should contain the following:

# no eol conversions!
* -text

This means the following:

  • [*]: this is a file filter and matches any file
  • [-text]: do not attempt to do any end-of-line conversion upon check-in and check-out

Note: using "text=auto" would mean: use the native end-of-line format on the checked out file (for anything that looks like text) and store it as "LF" internally.

This is robust because everyone that clones the repository will be using the same settings. (This is not the case when using core.autocrlf.)

See also Git documentation on gitattributes (effects: text).