Is there a file or menu that will let me change the settings on how to deal with line endings?
I read there are 3 options:
-
Checkout Windows-style, commit Unix-style
Git will convert LF to CRLF when checking out text files. When committing text files, CRLF will be converted to LF. For cross-platform projects, this is the recommended setting on Windows ("core.autocrlf" is set to "true")
-
Checkout as-is, commit Unix-style
Git will not perform any conversion when checking out text files. When committing text files, CRLF will be converted to LF. For cross-platform projects this is the recommended setting on Unix ("core.autocrlf" is set to "input").
-
Checkout as-is, commit as-is
Git will not perform any conversions when checking out or committing text files. Choosing this option is not recommended for cross-platform projects ("core.autocrlf" is set to "false")
The normal way to control this is with
git config
For example
git config --global core.autocrlf true
For details, scroll down in this link to Pro Git to the section named "core.autocrlf"
If you want to know what file this is saved in, you can run the command:
and the git global config file should open in a text editor, and you can see where that file was loaded from.
回答2
Line ending format used in OS:
CR
(Carriage Return\r
) andLF
(LineFeed\n
) pairLF
(LineFeed\n
)We can configure git to auto-correct line ending formats for each OS in two ways.
.gitattributes
fileGlobal Configuration
In Linux/OSX
This will fix any
CRLF
toLF
when you commit.In Windows
This will make sure that, when you checkout in windows, all
LF
will be converted toCRLF
..gitattributes File
It is a good idea to keep a
.gitattributes
file as we don‘t want to expect everyone in our team to set their own config. This file should be palced in the repository root and. If it exists, git will respect it.This will treat all files as text files and convert to OS‘s line ending on checkout and back to
LF
on commit automatically. If you want to specify the line ending explicitly, you can use:The first one is for checkout and the second one is for commit.
This will treat all
.jpg
images as binary files, regardless of path. So no conversion needed.Or you can add path qualifiers: