Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change line-ending settings

Tags:

git

msysgit

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:

  1. 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")

  2. 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").

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

like image 696
qwertymk Avatar asked May 02 '12 17:05

qwertymk


People also ask

How do I change the end of a line in git?

Global settings for line endings The git config core. autocrlf command is used to change how Git handles line endings. It takes a single argument. On Windows, you simply pass true to the configuration.

How do I know if a file is LF or CRLF?

use a text editor like notepad++ that can help you with understanding the line ends. It will show you the line end formats used as either Unix(LF) or Macintosh(CR) or Windows(CR LF) on the task bar of the tool. you can also go to View->Show Symbol->Show End Of Line to display the line ends as LF/ CR LF/CR.

How do you change line endings in Unix?

Converting using Notepad++ To write your file in this way, while you have the file open, go to the Edit menu, select the "EOL Conversion" submenu, and from the options that come up select "UNIX/OSX Format". The next time you save the file, its line endings will, all going well, be saved with UNIX-style line endings.


2 Answers

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:

git config --global --edit 

and the git global config file should open in a text editor, and you can see where that file was loaded from.

like image 128
CodingWithSpike Avatar answered Oct 02 '22 09:10

CodingWithSpike


Line ending format used in OS:

  • Windows: CR (Carriage Return \r) and LF (LineFeed \n) pair
  • OSX, Linux: LF (LineFeed \n)

We can configure git to auto-correct line ending formats for each OS in two ways.

  1. Git Global configuration
  2. Using .gitattributes file

Global Configuration

In Linux/OSX

git config --global core.autocrlf input 

This will fix any CRLF to LF when you commit.

In Windows

git config --global core.autocrlf true 

This will make sure that, when you checkout in windows, all LF will be converted to CRLF.

.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 placed in the repository root and. If it exists, git will respect it.

* text=auto 

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:

* text eol=crlf * text eol=lf 

The first one is for checkout and the second one is for commit.

*.jpg binary 

This will treat all .jpg images as binary files, regardless of path. So no conversion needed.

Or you can add path qualifiers:

my_path/**/*.jpg binary 
like image 33
Jasnan Avatar answered Oct 02 '22 11:10

Jasnan