IDEA中Line Separators Warning You are about to commot CRLF line separators to the Git repository

在IDEA中commit的時候,會遇到這個警告。html

其實只需將右下角爲CRLF的文件換爲LF就好了。git

 

詳細的關於這方面的,有一篇文章很是好:github

原文連接編程

目錄:windows

  1. 什麼是CRLF和LF
  2. 爲何要探究CRLF和LF
  3. 三種方式處理的不一樣
  4. 更多
  5. 參考文獻

一、什麼是CRLF和LF

CRLF 是carriagereturnline feed的縮寫。中文意思是回車換行。ide

LF是line feed的縮寫,中文意思是換行。學習

二、爲何要探究CRLF和LF

在學習git軟件,安裝git到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.

這裏面講到了作兩個操做(Checkout,Commit)的三種處理line endings的操做(Windows-style,Unix-style,As-is)。操作系統

爲何會出現這三種處理line endings(行尾結束符)呢?在Git的幫助頁面給出了很好的解釋。.net

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

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

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

When you view changes in a file, Git handles line endings in its own way.Since you're collaborating on projects with Git and GitHub, Git mightproduce unexpected results if, for example, you're working on a Windows machine,and your collaborator has made a change in OS X.

意思很好理解,就不翻譯了。重視因爲歷史的緣由,各類不一樣的操做系統在處理行尾結束符采起了不一樣的處理方法。而Git和GitHub

三、三種方式處理的不一樣

CRLF->Windows-style

LF->Unix Style

CR->Mac Style

CRLF表示句尾使用回車換行兩個字符(即咱們常在Windows編程時使用"\r\n"換行)

LF表示表示句尾,只使用換行.

CR表示只使用回車.

四、在Git中如何轉換?

在Git經過下面的命令配置

$git config --global core.autocrlf true
# Configure Git on Windows to properly handle line endings

解釋:core.autocrlf是git中負責處理line endings的變量,能夠設置三個值--true,inout,false.

設置成三個值會有什麼效果呢?

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

設置爲true,添加文件到git倉庫時,git將其視爲文本文件。他將把crlf變成lf。【2】

If core.autocrlf is set to false, no line-ending conversion is ever performed, so text files are checked in as-is. This usually works ok。【2】

設置爲false時,line-endings將不作轉換操做。文本文件保持原來的樣子。

設置爲input時,添加文件git倉庫石,git把crlf編程lf。當有人Check代碼時仍是lf方式。所以在window操做系統下,不要使用這個設置。

這是參考文獻2給的解釋但願能幫助你們。

Yet another way to show howautocrlf works

 
  1. 1) true: x -> LF -> CRLF

  2. 2) input: x -> LF -> LF

  3. 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

更多:

 

更爲複雜的配置命令見網站:https://www.kernel.org/pub/software/scm/git/docs/git-config.html

關於LF和CRLF討論見:http://stackoverflow.com/questions/1967370/git-replacing-lf-with-crlf

 

You can also provide a special--global flag, which makes Git usethe same settings for line endings acrossevery local Git repository on your computer.

參考文獻

【1】https://help.github.com/articles/dealing-with-line-endings

【2】http://stackoverflow.com/questions/1967370/git-replacing-lf-with-crlf

相關文章
相關標籤/搜索