GIT handles and modifies line terminator (CRLF and LF)

Source: Internet
Author: User
Tags lua using git

This paper is reproduced from http://www.tuicool.com/articles/IJjQVb

Table of Contents: What is CRLF and LF why to explore CRLF and LF three different ways to deal with the difference more reference 1, what is CRLF and LF

CRLF is the abbreviation of carriagereturnlinefeed. A carriage return wraps the line.

LF is an abbreviation for line feed, Chinese means wrapping. 2. Why to explore CRLF and LF

When you are learning git software, there are three options for installing git to configuring the lien ending conversion.

A. Checkout windows-style,commit Unix-style line endings.

B.checkout as-is,commit Unix-style Line endings.

C.checkout as-is,commit as-is Line endings.

This refers to three operations (Windows-style,unix-style,as-is) that do two operations (CHECKOUT,COMMIT) to handle line endings.

Why do these three line endings (End-of-line end characters) appear? A good explanation is given on Git's help page.

Reference from:https://help.github.com/articles/dealing-with-line-endings

If you are using Git to collaborate with others on GitHub, ensure that Git isproperly configured to handle line endings.

Every time for your press return on your keyboard you ' re actuallyinserting a invisible character-a line called. Historically, differentoperating systems have handled line endings differently.

When you view the changes in a file, Git handles line endings in its own way. Since you ' re collaborating in projects with Git and GitHub, git mightproduce unexpected-if, for results, you ' re wo Rking on a Windows Machine,and your collaborator has made a change in OS x.

The meaning is well understood and will not be translated. Due to historical reasons, various operating systems have adopted different processing methods in dealing with End-of-line Terminator. and Git and GitHub 3, three different ways to handle

Crlf->windows-style

Lf->unix Style

Cr->mac Style

Crlf the end of the sentence with a carriage return line two characters (that is, we often use "\ r \ n" to wrap in Windows programming)

LF is the end of the sentence, only the line wrap is used.

Cr indicates that only carriage returns are used. 4, how to transform in git.

After GIT is configured with the following command

$git config--global core.autocrlf true
# Configure git on Windows to properly handle line endings
Explanation: CORE.AUTOCRLF is the variable that is responsible for dealing with line endings in Git and can set three values--true,inout,false.

What's the effect of setting it to three values?

If Core.autocrlf is set to true, that means so any time you add a file to the git repo so git thinks is a text file, I T would turn all CRLF line endings to just LF before it stores it in the commit.

Set to True, Git treats the file as a text file when it is added to the Git warehouse. He will turn the CRLF into LF. "2"

If Core.autocrlf is set to False, no line-ending conversion are ever performed, so text files are checked in As-is. This is usually works OK. "2"

When set to False, Line-endings will not do the conversion operation. The text file stays the way it used to be.

When set to input, add files git warehouse stone, git to CRLF programming lf. When someone check the code is still in the LF way. Therefore, do not use this setting under the window operating system.

This is a reference to 2 of the explanations given in the hope of helping everyone.

Yet another way to show you AUTOCRLF works

1 true:             x-> LF-> CRLF
2) Input:            x-> LF-> LF
3) False:            x-> x-> x

where x is either CRLF (Windows-style) or LF (Unix-style) and arrows stand for

File to commit-> repository-> checked out file
More:

More complex configuration commands See Web site: https://www.kernel.org/pub/software/scm/git/docs/git-config.html

About LF and CRLF, see: Http://stackoverflow.com/questions/1967370/git-replacing-lf-with-crlf

can also provide a special--global flag, which makes Git usethe same settings for line endings across every local Git Repository on your computer. --------------------------------------------------------------------------------------------------------------- -----------------------------------------


This paper is reproduced from https://my.oschina.net/moooofly/blog/228467

Solve various problems caused by the difference between the end of different platforms, the need to set the CORE.AUTOCRLF to fix. Two kinds of hints that you might encounter:
WARNING:LF is replaced by CRLF Fatal:crlf would is replaced by LF
If you're writing a program on Windows, or you're working with someone else, they're programming on windows, and you're on another system, in which case you may experience a end-of-line end problem. This is because Windows uses a carriage return and a newline of two characters to end a row, while the MAC and Linux use only a newline character. While this is a minor problem, it can greatly disrupt cross-platform collaboration.

Git automatically converts the line terminator CRLF to LF when you submit, and converts LF to CRLF when the code is checked out. Use Core.autocrlf to turn on this feature, and if it is on a Windows system, set it to true so that if the code is checked out, the LF is converted to CRLF:

git config--global core.autocrlf true
Linux or MAC systems use LF as a line terminator, so you don't want git to automatically convert when you check out a file, and when a file with CRLF is accidentally introduced, you definitely want to fix it and set the CORE.AUTOCRLF to input to tell Git Convert the CRLF to LF at hand, and do not convert when checked out:
git config--global core.autocrlf input

By referring to the above configuration method, you can keep CRLF on a Windows system while checking out a file, while in the Mac and Linux system, including the warehouse, keep LF.

If you are a Windows programmer and you are developing a project that runs only on Windows, you can set false to cancel this feature and record the carriage return in the library:
git config--global core.autocrlf false


--------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------

Git handles line terminator

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.