我已经在Stack Overflow上阅读了很多不同的问题和答案,以及git的文档。自专制设置工作。
以下是我读到的内容:
Unix和Mac OSX (pre-OSX使用CR)客户端使用LF行结束符。 Windows客户端使用CRLF行结束符。
当核心。在客户端被设置为true, git存储库总是以LF行结束格式存储文件,客户端文件中的行结束符在签出/提交时来回转换,对于使用非LF行结束符的客户端(即Windows),无论客户端上的行结束符文件是什么格式(这与Tim Clem的定义不一致-参见下面的更新)。
下面是一个矩阵,它试图为core的'input'和'false'设置记录相同的内容。带问号的自专制,我不确定行结束转换行为。
我的问题是:
问号应该是什么? 这个矩阵对“非问号”正确吗?
当达成共识时,我将更新答案中的问号。
core.autocrlf value true input false ---------------------------------------------------------- commit | convert ? ? new | to LF (convert to LF?) (no conversion?) commit | convert to ? no existing | LF (convert to LF?) conversion checkout | convert to ? no existing | CRLF (no conversion?) conversion
我并不是真的在寻找各种设置的利弊。我只是寻找数据,使它清楚地期望git如何操作这三个设置中的每一个。
--
2012年4月17日更新:在阅读了评论中JJD链接的Tim Clem的文章后,我修改了上表中“未知”值中的一些值,以及更改“checkout现有| true转换为CRLF而不是转换为客户端”。以下是他给出的定义,比我在其他地方看到的任何定义都更清楚:
核心。独裁者= false
This is the default, but most people are encouraged to change this immediately. The result of using false is that Git doesn’t ever mess with line endings on your file. You can check in files with LF or CRLF or CR or some random mix of those three and Git does not care. This can make diffs harder to read and merges more difficult. Most people working in a Unix/Linux world use this value because they don’t have CRLF problems and they don’t need Git to be doing extra work whenever files are written to the object database or written out into the working directory.
核心。独裁者= true
这意味着Git将处理所有文本文件,并确保 在将该文件写入对象数据库时,CRLF将被LF替换 并在写入工作时将所有LF转回CRLF 目录中。这是Windows上的推荐设置,因为它 确保您的存储库可以在其他平台上使用 在工作目录中保留CRLF。
核心。selflf =输入
This means that Git will process all text files and make sure that CRLF is replaced with LF when writing that file to the object database. It will not, however, do the reverse. When you read files back out of the object database and write them into the working directory they will still have LFs to denote the end of line. This setting is generally used on Unix/Linux/OS X to prevent CRLFs from getting written into the repository. The idea being that if you pasted code from a web browser and accidentally got CRLFs into one of your files, Git would make sure they were replaced with LFs when you wrote to the object database.
Tim的文章非常棒,我能想到的唯一缺失的是他假设存储库是LF格式的,这并不一定是正确的,特别是对于仅用于Windows的项目。
将Tim的文章与jmlane迄今为止投票最多的答案进行比较,可以发现在正确设置和输入设置上完全一致,而在错误设置上存在分歧。