does a git repository have its own local value for core.autocrlf that overrides the global one?
Asked Answered
A

2

16

As per this question, I understand that core.autocrlf=true in git will cause CRLF to LF translations.

However when I type : git config core.autocrlf

I see: false

However, when I stage modified files that are already in the repo, I still get these warnings:

Warning: CRLF will be replaced by LF in File1.X.
The file will have its original line endings in your working directory.

My guess is that the repo copy of the file is already set to "autocrlf=true".

Questions: A. How do I query whether a file or git repo is already forcing AutoCrlf? B. How do I turn it autocrlf off?

Ayakoayala answered 9/9, 2012 at 15:36 Comment(2)
I would like to know if you can have a "local" copy of the .gitattributes file that you DON'T check into source control? I'd like to have some repos be "windows style" settings and only 1 repo to be LINUX style, without forcing all users of that repo to use LINUX. Is this possible?Counterword
Can you put in a git global setting that only applies locally to a particular directory (i.e. REPO)? I want some repos to be WINDOWS and some to be LINUX style line endings?Counterword
G
8

Git allows you to override your global setting on a per-repository basis with a .gitattributes file. You put it in the root directory of the repository, and becomes a file committed as part of the repository. I suspect this is happening in your case.

Github has a good page on this: https://help.github.com/articles/dealing-with-line-endings

In short, you can use the text attribute to set the line endings for a particular file extension. For instance, forcing sln files to CRLF would require the following line in a .gitattributes file :

# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf
Googolplex answered 23/10, 2012 at 1:8 Comment(4)
Right... so... what would I put in .gitattributes that would be the equivalent of core.autocrlf=false in my global config?Path
So would the following in .gitattributes be equivalent to core.autocrlf=false? * -textPath
No. .gitattributes also affects ability to merge if you remove binary.Lubbock
This answer did not actually answer the specific question asked, so it should not have been marked as the answer. I came here looking for an answer to the exact same question: how do I simply set core.autocrlf=false per-repo? I don't want to have to explicitly list out specific EOL types to use for specific files or file extensions. I just want the entire Git repo to always be shown to all developers of it verbatim, without mangling EOLs in any file type, ever.Prolactin
V
1

You can unset the text attribute for everything in order to stop git from messing with the line endings in your repo's .gitattributes [1]:

* -text

[1] https://git-scm.com/docs/gitattributes#Documentation/gitattributes.txt-Unset-1

Unset Unsetting the text attribute on a path tells Git not to attempt any end-of-line conversion upon checkin or checkout.

Ventral answered 11/6 at 11:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.