29

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?

1
  • Did you find a solution to this? It's almost a year and I am in same boat. I am working in git and using git-tf for my workflow. I commit to TFS once in a while (git tfs rcheckin). This screws up the line endings in TFS (converts to LF). Commented Feb 24, 2015 at 23:07

1 Answer 1

26

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).

Sign up to request clarification or add additional context in comments.

4 Comments

OMFG! Why does not by default we have that in TFS! Thank you so much.
This doesn't work for me (SourceTree GUI on macOS). I tried to match any .c file and make Git ignore the line-endings. Checked in .gitattributes file with *.c -text or **/*.c -text, both don't work. After I change line-endings in a .c file Git still picks it up. Also tried a fresh checkout of the repo. Any ideas?
@Paco1 The described change tells git to not manipulate the line-endings. Git leaves the line-endings as they were committed. So it does not have the effect that you expect.
Oh, I see. I thought my and OP's issue are similar, only the in the other direction (line-endings changed in repo vs locally).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.