Information Technology Reference
In-Depth Information
Hint
The command
$ git diff
has a very useful parameter
--check
that can
be used to verify that the commit does not introduce changes that affect only white char-
acters. The command
$ git diff --check
reports problems with the handling of
white characters.
13-2. Committing files without line-end-
ing conversion
Problem
You want to start a new repository that contains text files with different types of line
endings. Some of them use Linux-like line endings that consist of a single
LF
charac-
ter, some of them use Windows-like line endings consisting of two characters
CRLF
.
Your repository even contains files using both types:
LF
and
CRLF
that are mixed in a
single file. You want to commit all the files without any conversion of line-ending
characters.
Hint
At first, you may consider the files using both
LF
and
CRLF
to be corrupted.
But you may need them anyway. I found them very useful as the static fixtures to tests
when I was working on a library to process text files produced by external tools. It
turned out that the applications I used generated corrupted files containing not only
LF
and
CRLF
but also
CR
as line endings. All three were mixed in a single file!
Solution
Initialize a new repository:
$ cd git-recipes
$ mkdir 13-02
$ cd 13-02
$ git init