Information Technology Reference
In-Depth Information
*
eol=lf
windows/*
eol=crlf
mixed/*
-text
Finally commit all files using the
$ git snapshot Initial commit
com-
mand.
The repository now contains the very accurate rules that define the line endings con-
version. Now, if anyone clones the repository, then, no matter what his or her settings
are, the cloned repository will contain exactly the same line endings that we used with-
in
$ print
commands. To verify this set the
core.autocrlf
to
true
with:
$ git config --global core.autocrlf true
And then clone the repository:
$ cd ..
$ git clone 13-07 13-07-verification
$ cd 13-07-verification
The command:
$ hexdump -c linux/abcd.txt
prints the contents of the file with
LF
line endings. This proves that even though
core.autocrlf
was set to
true
no conversion was performed.
How It Works
The rule
* eol=lf
forces git to always checkout all files using
LF
line endings.
Thus, by default, all the files will use
LF
encoding. Files stored under the
linux/
dir-
ectory in particular. The second rule, which is
windows/* eol=crlf
, defines an
exception to the first rule. When checking out files stored under the
windows/
direct-
ory,
CRLF
will be used. The last rule,
mixed/* -text
, turns off all the conversions
of line endings for all files stored under the
mixed/
directory.
The configuration written in the
.gitattributes
file overrides settings defined
with the
$ git config
command. Therefore, no matter what your settings are, the
working directory of the project will always stick to the predefined assumptions: