Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to find crlf line separators with git?

as I want to commit to git using intellij, I get a message

You are about to commit CRLF line separators to the Git repository

and I am given 2 options:

  • fix and commit (runs git config --global core.autocrlf)
  • commit as is

I would like to see where those line separators are before I do anything else.

How can I do that with git or intellij? (solutions using only git are preferred).

like image 984
guy mograbi Avatar asked Jul 07 '14 05:07

guy mograbi


People also ask

What is CRLF line separators git?

There are two ways to represent a line ending in a source code file. CRLF (carriage return + line feed); or just LF (line feed).

Where are CRLF line separators in Intellij?

From the main menu, select File | File Properties | Line Separators, and then select a line ending style from the list.

How do I see line endings in github?

To tell what line endings a file in the repository is using, use git show to extract the file's contents. This will give you the contents without changing the line endings.

Does git use LF or CRLF?

Git doesn't expect you to use unix-style LF under Windows. The warning "CRLF will be replaced by LF" says that you (having autocrlf = input ) will lose your windows-style CRLF after a commit-checkout cycle (it will be replaced by unix-style LF). Don't use input under Windows.


1 Answers

You could use git grep via the command line to search for files containing the windows style newline characters.

Using the git bash you can find all files which contain a \r character via the following command (bash only!):

git grep -Il $'\r' 

Or alternativly (which should work for all shell types - except windows ones):

git grep -Il '<CTRL + M>' 

This will actually display as a newline in your shell, but as long as you wrap it into quotes it will work.

And finally for the windows CLI (tested with CMD and PowerShell):

git grep -Il "\r" 

Used options

  • -I excludes binary files from the match
  • -l shows only the file names with matches, rather than all matches

Also, if you want to restrict your search on a number of files you can use the --cached option, which will only search in files you have on your index.

You can read the documentation for more information.

like image 128
Sascha Wolf Avatar answered Sep 29 '22 21:09

Sascha Wolf