Home git How to configure autocrlf in git for different systems?

How to configure autocrlf in git for different systems?

Author

Date

Category

If I understand correctly, then in Windows when Autocrlf = True Git will make the CRLF – & gt conversion lf after commit, and lf – & gt; CRLF when checkout.

In my workflow, there are cases when the source files are reset manually, bypassing the repository, from the Linux / Windows first machine repository work directory to the Windows Machine Working Directory.

In this case, in these source files, the strings contain LF – the flow, and in the operating directory of the second machine CRLF . Does this mean that you have to manually convert by third-party software to CRLF ?

How to configure core.autocrlf on both working machines to avoid errors when “manual” file transfer?

Suppose that in Windows – Autocrlf = True , and in Linux – Autocrlf = Input (To prevent the case above, only with CRLF ).


Answer 1, Authority 100%

I tested all the options and that came out:

╔══════════════════════════ ═══════════════════════════════════╗
║ Core.Autocrlf ║ FALSE ║ INPUT ║ TRUE ║
╠══════════════════════════════════════════════════ ═════════╣
║ Git Commit ║ lf = & gt; Lf ║ lf = & gt; Lf ║ lf = & gt; CRLF ║
║ ║ CR = & GT; Cr ║ CR = & GT; Cr ║ CR = & GT; CR ║
║ ║ CRLF = & GT; CRLF ║ CRLF = & GT; LF ║ CRLF = & GT; CRLF ║
╠══════════════════════════════════════════════════ ═════════╣
║ Git Checkout ║ LF = & GT; Lf ║ lf = & gt; Lf ║ lf = & gt; CRLF ║
║ ║ CR = & GT; Cr ║ CR = & GT; Cr ║ CR = & GT; CR ║
║ ║ CRLF = & GT; CRLF ║ CRLF = & GT; CRLF ║ CRLF = & GT; CRLF ║
╚══════════════════════════════════════════════════ ═════════╝

I think that the most optimal option on all CORE.AUTOCRLF = INPUT . At the same time, on all the end of the row CRLF , if necessary, it will be implicitly converted to LF if there is already LF , it will remain.


Answer 2, Authority 83%

How to properly configure Core.Autocrlf on both working machines to avoid errors when “manual” file transfer?

I think in all operating systems it makes sense to assign to this attribute at least the value of input .

Then when adding “abnormalized” files (i.e., with a row separator CRLF ), a warning will be issued that the file in the repository will be converted, and upon subsequently, the files will be automatically “normalized” (The CRLF separator will be replaced by lf ).

And when executing the checkout command, there will be no transformations – the files in the working copy will have the same separators as in the 1 repository.

Perhaps in operating systems, where by default the separator is not lf , and crlf (for example, ms / windows ), it makes sense “Go further” and assign the attribute core.autocrlf true – to and when the checkout command was transformed LF crlf . But this probably makes sense only if the program used to view / edit these files displays the contents of the files incorrectly (i.e., does not transfer the line, having met the lf symbol).


1 – see exactly how the file is stored in the repository, you can, for example, using the Git Cat-File -p command Hash . Example:

Initialize repository:

$ git init

Add two lines to the file and make a commit:

$ echo 1 & gt; File; Echo 2 & gt; & gt; File
$ Git Add File
$ Git Commit -m 1
[Master (root-commit) 1373ad1] 1
 1 File Changed, 2 Insertions (+)
 Create Mode 100644 File

We view the contents of the commit, indicating its hash (can be abbreviated):

$ Git Cat-File -p 1373ad1
Tree D25D3B6082891168B6787CB20783BD332E5B8F74.
...

We view an object type Tree added by this commit:

$ git cat-file -p d25d3b6
100644 BLOB 1191247B6D9A206F6BA3D8AC79E26D041DD86941 File

We view an object type blob containing the same file:

$ Git Cat-File -p 1191247 | Hexdump -C.
00000000 31 0A 32 0A | 1.2. |
00000004.

And we see that it has been preserved in a repository with a divider of rows lf .

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions