mirror of
https://github.com/git/git.git
synced 2026-04-05 14:30:10 +02:00
Merge branch 'eb/core-eol' into next
* eb/core-eol: Add "core.eol" config variable Rename the "crlf" attribute "text" Add per-repository eol normalization Add tests for per-repository eol normalization Conflicts: Documentation/config.txt Makefile
This commit is contained in:
@@ -196,20 +196,17 @@ core.quotepath::
|
||||
quoted without `-z` regardless of the setting of this
|
||||
variable.
|
||||
|
||||
core.autocrlf::
|
||||
If true, makes git convert `CRLF` at the end of lines in text files to
|
||||
`LF` when reading from the work tree, and convert in reverse when
|
||||
writing to the work tree. The variable can be set to
|
||||
'input', in which case the conversion happens only while
|
||||
reading from the work tree but files are written out to the work
|
||||
tree with `LF` at the end of lines. A file is considered
|
||||
"text" (i.e. be subjected to the autocrlf mechanism) based on
|
||||
the file's `crlf` attribute, or if `crlf` is unspecified,
|
||||
based on the file's contents. See linkgit:gitattributes[5].
|
||||
core.eol::
|
||||
Sets the line ending type to use in the working directory for
|
||||
files that have the `text` property set. Alternatives are
|
||||
'lf', 'crlf' and 'native', which uses the platform's native
|
||||
line ending. The default value is `native`. See
|
||||
linkgit:gitattributes[5] for more information on end-of-line
|
||||
conversion.
|
||||
|
||||
core.safecrlf::
|
||||
If true, makes git check if converting `CRLF` as controlled by
|
||||
`core.autocrlf` is reversible. Git will verify if a command
|
||||
If true, makes git check if converting `CRLF` is reversible when
|
||||
end-of-line conversion is active. Git will verify if a command
|
||||
modifies a file in the work tree either directly or indirectly.
|
||||
For example, committing a file followed by checking out the
|
||||
same file should yield the original file in the work tree. If
|
||||
@@ -219,7 +216,7 @@ core.safecrlf::
|
||||
irreversible conversion but continue the operation.
|
||||
+
|
||||
CRLF conversion bears a slight chance of corrupting data.
|
||||
autocrlf=true will convert CRLF to LF during commit and LF to
|
||||
When it is enabled, git will convert CRLF to LF during commit and LF to
|
||||
CRLF during checkout. A file that contains a mixture of LF and
|
||||
CRLF before the commit cannot be recreated by git. For text
|
||||
files this is the right thing to do: it corrects line endings
|
||||
@@ -243,15 +240,25 @@ converting CRLFs corrupts data.
|
||||
+
|
||||
Note, this safety check does not mean that a checkout will generate a
|
||||
file identical to the original file for a different setting of
|
||||
`core.autocrlf`, but only for the current one. For example, a text
|
||||
file with `LF` would be accepted with `core.autocrlf=input` and could
|
||||
later be checked out with `core.autocrlf=true`, in which case the
|
||||
`core.eol` and `core.autocrlf`, but only for the current one. For
|
||||
example, a text file with `LF` would be accepted with `core.eol=lf`
|
||||
and could later be checked out with `core.eol=crlf`, in which case the
|
||||
resulting file would contain `CRLF`, although the original file
|
||||
contained `LF`. However, in both work trees the line endings would be
|
||||
consistent, that is either all `LF` or all `CRLF`, but never mixed. A
|
||||
file with mixed line endings would be reported by the `core.safecrlf`
|
||||
mechanism.
|
||||
|
||||
core.autocrlf::
|
||||
Setting this variable to "true" is almost the same as setting
|
||||
the `text` attribute to "auto" on all files except that text
|
||||
files are not guaranteed to be normalized: files that contain
|
||||
`CRLF` in the repository will not be touched. Use this
|
||||
setting if you want to have `CRLF` line endings in your
|
||||
working directory even though the repository does not have
|
||||
normalized line endings. This variable can be set to 'input',
|
||||
in which case no output conversion is performed.
|
||||
|
||||
core.symlinks::
|
||||
If false, symbolic links are checked out as small plain files that
|
||||
contain the link text. linkgit:git-update-index[1] and
|
||||
@@ -979,13 +986,15 @@ gitcvs.logfile::
|
||||
various stuff. See linkgit:git-cvsserver[1].
|
||||
|
||||
gitcvs.usecrlfattr::
|
||||
If true, the server will look up the `crlf` attribute for
|
||||
files to determine the '-k' modes to use. If `crlf` is set,
|
||||
the '-k' mode will be left blank, so cvs clients will
|
||||
treat it as text. If `crlf` is explicitly unset, the file
|
||||
If true, the server will look up the end-of-line conversion
|
||||
attributes for files to determine the '-k' modes to use. If
|
||||
the attributes force git to treat a file as text,
|
||||
the '-k' mode will be left blank so cvs clients will
|
||||
treat it as text. If they suppress text conversion, the file
|
||||
will be set with '-kb' mode, which suppresses any newline munging
|
||||
the client might otherwise do. If `crlf` is not specified,
|
||||
then 'gitcvs.allbinary' is used. See linkgit:gitattributes[5].
|
||||
the client might otherwise do. If the attributes do not allow
|
||||
the file type to be determined, then 'gitcvs.allbinary' is
|
||||
used. See linkgit:gitattributes[5].
|
||||
|
||||
gitcvs.allbinary::
|
||||
This is used if 'gitcvs.usecrlfattr' does not resolve
|
||||
|
||||
@@ -369,16 +369,13 @@ By default the server leaves the '-k' mode blank for all files,
|
||||
which causes the cvs client to treat them as a text files, subject
|
||||
to crlf conversion on some platforms.
|
||||
|
||||
You can make the server use `crlf` attributes to set the '-k' modes
|
||||
for files by setting the `gitcvs.usecrlfattr` config variable.
|
||||
In this case, if `crlf` is explicitly unset ('-crlf'), then the
|
||||
server will set '-kb' mode for binary files. If `crlf` is set,
|
||||
then the '-k' mode will explicitly be left blank. See
|
||||
also linkgit:gitattributes[5] for more information about the `crlf`
|
||||
attribute.
|
||||
You can make the server use the end-of-line conversion attributes to
|
||||
set the '-k' modes for files by setting the `gitcvs.usecrlfattr`
|
||||
config variable. See linkgit:gitattributes[5] for more information
|
||||
about end-of-line conversion.
|
||||
|
||||
Alternatively, if `gitcvs.usecrlfattr` config is not enabled
|
||||
or if the `crlf` attribute is unspecified for a filename, then
|
||||
or the attributes do not allow automatic detection for a filename, then
|
||||
the server uses the `gitcvs.allbinary` config for the default setting.
|
||||
If `gitcvs.allbinary` is set, then file not otherwise
|
||||
specified will default to '-kb' mode. Otherwise the '-k' mode
|
||||
|
||||
@@ -92,53 +92,154 @@ such as 'git checkout' and 'git merge' run. They also affect how
|
||||
git stores the contents you prepare in the working tree in the
|
||||
repository upon 'git add' and 'git commit'.
|
||||
|
||||
`crlf`
|
||||
`text`
|
||||
^^^^^^
|
||||
|
||||
This attribute controls the line-ending convention.
|
||||
This attribute enables and controls end-of-line normalization. When a
|
||||
text file is normalized, its line endings are converted to LF in the
|
||||
repository. To control what line ending style is used in the working
|
||||
directory, use the `eol` attribute for a single file and the
|
||||
`core.eol` configuration variable for all text files.
|
||||
|
||||
Set::
|
||||
|
||||
Setting the `crlf` attribute on a path is meant to mark
|
||||
the path as a "text" file. 'core.autocrlf' conversion
|
||||
takes place without guessing the content type by
|
||||
inspection.
|
||||
Setting the `text` attribute on a path enables end-of-line
|
||||
normalization and marks the path as a text file. End-of-line
|
||||
conversion takes place without guessing the content type.
|
||||
|
||||
Unset::
|
||||
|
||||
Unsetting the `crlf` attribute on a path tells git not to
|
||||
Unsetting the `text` attribute on a path tells git not to
|
||||
attempt any end-of-line conversion upon checkin or checkout.
|
||||
|
||||
Set to string value "auto"::
|
||||
|
||||
When `text` is set to "auto", the path is marked for automatic
|
||||
end-of-line normalization. If git decides that the content is
|
||||
text, its line endings are normalized to LF on checkin.
|
||||
|
||||
Unspecified::
|
||||
|
||||
Unspecified `crlf` attribute tells git to apply the
|
||||
`core.autocrlf` conversion when the file content looks
|
||||
like text.
|
||||
If the `text` attribute is unspecified, git uses the
|
||||
`core.autocrlf` configuration variable to determine if the
|
||||
file should be converted.
|
||||
|
||||
Set to string value "input"::
|
||||
Any other value causes git to act as if `text` has been left
|
||||
unspecified.
|
||||
|
||||
This is similar to setting the attribute to `true`, but
|
||||
also forces git to act as if `core.autocrlf` is set to
|
||||
`input` for the path.
|
||||
`eol`
|
||||
^^^^^
|
||||
|
||||
Any other value set to `crlf` attribute is ignored and git acts
|
||||
as if the attribute is left unspecified.
|
||||
This attribute sets a specific line-ending style to be used in the
|
||||
working directory. It enables end-of-line normalization without any
|
||||
content checks, effectively setting the `text` attribute.
|
||||
|
||||
Set to string value "crlf"::
|
||||
|
||||
The `core.autocrlf` conversion
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
This setting forces git to normalize line endings for this
|
||||
file on checkin and convert them to CRLF when the file is
|
||||
checked out.
|
||||
|
||||
If the configuration variable `core.autocrlf` is false, no
|
||||
conversion is done.
|
||||
Set to string value "lf"::
|
||||
|
||||
When `core.autocrlf` is true, it means that the platform wants
|
||||
CRLF line endings for files in the working tree, and you want to
|
||||
convert them back to the normal LF line endings when checking
|
||||
in to the repository.
|
||||
This setting forces git to normalize line endings to LF on
|
||||
checkin and prevents conversion to CRLF when the file is
|
||||
checked out.
|
||||
|
||||
When `core.autocrlf` is set to "input", line endings are
|
||||
converted to LF upon checkin, but there is no conversion done
|
||||
upon checkout.
|
||||
Backwards compatibility with `crlf` attribute
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
For backwards compatibility, the `crlf` attribute is interpreted as
|
||||
follows:
|
||||
|
||||
------------------------
|
||||
crlf text
|
||||
-crlf -text
|
||||
crlf=input eol=lf
|
||||
------------------------
|
||||
|
||||
End-of-line conversion
|
||||
^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
While git normally leaves file contents alone, it can be configured to
|
||||
normalize line endings to LF in the repository and, optionally, to
|
||||
convert them to CRLF when files are checked out.
|
||||
|
||||
Here is an example that will make git normalize .txt, .vcproj and .sh
|
||||
files, ensure that .vcproj files have CRLF and .sh files have LF in
|
||||
the working directory, and prevent .jpg files from being normalized
|
||||
regardless of their content.
|
||||
|
||||
------------------------
|
||||
*.txt text
|
||||
*.vcproj eol=crlf
|
||||
*.sh eol=lf
|
||||
*.jpg -text
|
||||
------------------------
|
||||
|
||||
Other source code management systems normalize all text files in their
|
||||
repositories, and there are two ways to enable similar automatic
|
||||
normalization in git.
|
||||
|
||||
If you simply want to have CRLF line endings in your working directory
|
||||
regardless of the repository you are working with, you can set the
|
||||
config variable "core.autocrlf" without changing any attributes.
|
||||
|
||||
------------------------
|
||||
[core]
|
||||
autocrlf = true
|
||||
------------------------
|
||||
|
||||
This does not force normalization of all text files, but does ensure
|
||||
that text files that you introduce to the repository have their line
|
||||
endings normalized to LF when they are added, and that files that are
|
||||
already normalized in the repository stay normalized.
|
||||
|
||||
If you want to interoperate with a source code management system that
|
||||
enforces end-of-line normalization, or you simply want all text files
|
||||
in your repository to be normalized, you should instead set the `text`
|
||||
attribute to "auto" for _all_ files.
|
||||
|
||||
------------------------
|
||||
* text=auto
|
||||
------------------------
|
||||
|
||||
This ensures that all files that git considers to be text will have
|
||||
normalized (LF) line endings in the repository. The `core.eol`
|
||||
configuration variable controls which line endings git will use for
|
||||
normalized files in your working directory; the default is to use the
|
||||
native line ending for your platform, or CRLF if `core.autocrlf` is
|
||||
set.
|
||||
|
||||
NOTE: When `text=auto` normalization is enabled in an existing
|
||||
repository, any text files containing CRLFs should be normalized. If
|
||||
they are not they will be normalized the next time someone tries to
|
||||
change them, causing unfortunate misattribution. From a clean working
|
||||
directory:
|
||||
|
||||
-------------------------------------------------
|
||||
$ echo "* text=auto" >>.gitattributes
|
||||
$ rm .git/index # Remove the index to force git to
|
||||
$ git reset # re-scan the working directory
|
||||
$ git status # Show files that will be normalized
|
||||
$ git add -u
|
||||
$ git add .gitattributes
|
||||
$ git commit -m "Introduce end-of-line normalization"
|
||||
-------------------------------------------------
|
||||
|
||||
If any files that should not be normalized show up in 'git status',
|
||||
unset their `text` attribute before running 'git add -u'.
|
||||
|
||||
------------------------
|
||||
manual.pdf -text
|
||||
------------------------
|
||||
|
||||
Conversely, text files that git does not detect can have normalization
|
||||
enabled manually.
|
||||
|
||||
------------------------
|
||||
weirdchars.txt text
|
||||
------------------------
|
||||
|
||||
If `core.safecrlf` is set to "true" or "warn", git verifies if
|
||||
the conversion is reversible for the current setting of
|
||||
@@ -223,11 +324,11 @@ Interaction between checkin/checkout attributes
|
||||
In the check-in codepath, the worktree file is first converted
|
||||
with `filter` driver (if specified and corresponding driver
|
||||
defined), then the result is processed with `ident` (if
|
||||
specified), and then finally with `crlf` (again, if specified
|
||||
specified), and then finally with `text` (again, if specified
|
||||
and applicable).
|
||||
|
||||
In the check-out codepath, the blob content is first converted
|
||||
with `crlf`, and then `ident` and fed to `filter`.
|
||||
with `text`, and then `ident` and fed to `filter`.
|
||||
|
||||
|
||||
Generating diff text
|
||||
@@ -651,7 +752,7 @@ You do not want any end-of-line conversions applied to, nor textual diffs
|
||||
produced for, any binary file you track. You would need to specify e.g.
|
||||
|
||||
------------
|
||||
*.jpg -crlf -diff
|
||||
*.jpg -text -diff
|
||||
------------
|
||||
|
||||
but that may become cumbersome, when you have many attributes. Using
|
||||
@@ -664,7 +765,7 @@ the same time. The system knows a built-in attribute macro, `binary`:
|
||||
|
||||
which is equivalent to the above. Note that the attribute macros can only
|
||||
be "Set" (see the above example that sets "binary" macro as if it were an
|
||||
ordinary attribute --- setting it in turn unsets "crlf" and "diff").
|
||||
ordinary attribute --- setting it in turn unsets "text" and "diff").
|
||||
|
||||
|
||||
DEFINING ATTRIBUTE MACROS
|
||||
@@ -675,7 +776,7 @@ at the toplevel (i.e. not in any subdirectory). The built-in attribute
|
||||
macro "binary" is equivalent to:
|
||||
|
||||
------------
|
||||
[attr]binary -diff -crlf
|
||||
[attr]binary -diff -text
|
||||
------------
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user