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


Solution 1:

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.