Git core.autocrlf 行尾默认设置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39408793/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git core.autocrlf line ending default setting
提问by Pensierinmusica
I'm trying to figure out what is the default value for core.autocrlf
in Git if the user doesn't change this setting.
core.autocrlf
如果用户不更改此设置,我试图弄清楚Git 中的默认值是什么。
I've looked in the docs but can't find this info. Can you please point me in the right direction?
我查看了文档,但找不到此信息。你能指出我正确的方向吗?
Specifically, on a fresh Git install, would Git automatically convert Windows line endings to Unix when committing to a repo from a Windows system?
具体来说,在全新的 Git 安装中,当从 Windows 系统提交到存储库时,Git 是否会自动将 Windows 行尾转换为 Unix?
Thanks!
谢谢!
采纳答案by LightBender
Checking the git source code, core.autocrlf is set to false by default. (And has been since the property's original introduction on Feb 13, 2007, though it has since been converted from a static value to a constant.)
查看git源代码,core.autocrlf默认设置为false。(并且自该属性于2007年2 月 13 日最初引入以来一直存在,尽管它已从静态值转换为常量。)
The Windows installer does require you to pick a value for this property which is explicitly set in the git system config.
Windows 安装程序确实要求您为此属性选择一个值,该值在 git 系统配置中明确设置。
回答by Claudio
It is difficult to find this stated but I could figure out by trial and error that:
很难找到这种说法,但我可以通过反复试验找出:
the default value is "false"
Windows installer let you choose the desired behavior but by default (if you install without changing proposed settings) it sets it to "true". This is not the software default, the installer sets the core.autocrlf system setting.
默认值为“假”
Windows 安装程序允许您选择所需的行为,但默认情况下(如果您在不更改建议设置的情况下安装)它将其设置为“true”。这不是软件默认设置,安装程序会设置 core.autocrlf 系统设置。
"false" means no processing on line endings "true" means checking in as LF and checking out according to system (CRLF on Windows and LF on Unix).
"false" 表示不对行尾进行处理 "true" 表示作为 LF 签入并根据系统签出(Windows 上为 CRLF,Unix 上为 LF)。
When Unix and Windows are both used it is advisable to use "false" on Unix (because automatic conversion can break some binary files that look line text files and Unix uses LF anyway) and "true" on Windows (otherwise the repository is filled with CRLF which is causing compatibility issues).
当 Unix 和 Windows 同时使用时,建议在 Unix 上使用“false”(因为自动转换会破坏一些看起来像行文本文件的二进制文件,而 Unix 无论如何都使用 LF)和在 Windows 上使用“true”(否则存储库充满导致兼容性问题的 CRLF)。
回答by Dmitriy
You can list all config key-values by issuing this command
您可以通过发出此命令列出所有配置键值
git config --list
And as I see the default is
正如我所见,默认是
core.autocrlf=true
core.autocrlf=真
Although this is the setting I chose(or better to say "not touched") when I was installing Git for Windows
尽管这是我在为 Windows 安装 Git 时选择的设置(或者最好说“未触及”)
回答by teebszet
For the purposes of OP's specific situation, and also in case of cross-platform differences, global .gitconfig file, and local .gitconfig file, the best way to determine this should be to run:
考虑到 OP 的具体情况,以及跨平台差异、全局 .gitconfig 文件和本地 .gitconfig 文件,确定这一点的最佳方法应该是运行:
git config core.autocrlf
git config core.autocrlf
after the clean install of Git to find out which setting prevails.
在干净安装 Git 之后找出哪个设置占优势。
Note that the output of the command will change depending on your current working directory (and its local .gitconfig)
请注意,命令的输出将根据您当前的工作目录(及其本地 .gitconfig)而变化
NOTE:
笔记:
The comment describing the same command on Unix actually does work, but poster had used the wrong config key. It should be core.autocrlf, not autocrlf.
在 Unix 上描述相同命令的注释实际上确实有效,但发布者使用了错误的配置键。它应该是 core.autocrlf,而不是 autocrlf。
Documentation on git-scm.com/book/en/v2/Customizing-Git-Git-Configuration lists three options but doesn't say which is default, and on my clean install on Ubuntu git config --list gives no entry for autocrlf, git config --get autocrlf returns error: key does not contain a section: autocrlf. Presumably this means default is false but it'd be good to have this confirmed.
git-scm.com/book/en/v2/Customizing-Git-Git-Configuration 上的文档列出了三个选项,但没有说明哪个是默认选项,并且在我在 Ubuntu 上进行全新安装时 git config --list 没有提供 autocrlf 条目, git config --get autocrlf 返回错误:密钥不包含部分:autocrlf。大概这意味着 default 是 false 但最好确认一下。
回答by Sanster
If you're using the newest window installer of git, the default option of core.autoclrf is false .
如果您使用的是 git 的最新窗口安装程序,则 core.autoclrf 的默认选项是 false 。