Information Technology Reference
In-Depth Information
Create three files stored in separate directories:
$ mkdir linux
$ mkdir mixed
$ mkdir windows
$ printf "linux \n a \n b \n c \n d" > linux/abcd.txt
$ printf "mixed \n a \r\n b \n c \r\n d" > mixed/abcd.txt
$ printf "windows \r\n a \r\n b \r\n c \r\n d" > windows/
abcd.txt
The first named
linux/abcd.txt
uses
LF
line endings (they are usually en-
coded as
\n
in strings). The second file named
mixed/abcd.txt
contains both
LF
and
CRLF
line endings. The last file named
windows/abcd.txt
uses
CRLF
line
endings. These, when embedded in strings, are written as
\r\n
. You can verify line
endings using the following commands:
$ hexdump -c linux/abcd.txt
$ hexdump -c mixed/abcd.txt
$ hexdump -c windows/abcd.txt
To commit files without any conversion of new lines turn off the
core.autocrlf
setting:
$ git config --local core.autocrlf false
Commit the files:
$ git add -A
$ git commit -m "Three files: linux, windows and mixed
line endings"
Now the most recent commit stored in the database
.git/objects
contains the
following line endings:
•
linux/abcd.txt
uses
LF
•
mixed/abcd.txt
uses both
LF
and
CRLF
•
windows/abcd.txt
uses
CRLF