git 如何使用git找到crlf行分隔符?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24603649/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:11:09  来源:igfitidea点击:

how to find crlf line separators with git?

gitintellij-idea

提问by guy mograbi

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

因为我想使用 intellij 提交到 git,我收到一条消息

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

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
  • 修复并提交(运行git config --global core.autocrlf
  • 按原样提交

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

我怎样才能用 git 或 intellij 做到这一点?(仅使用 git 的解决方案是首选)。

采纳答案by Sascha Wolf

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

您可以git grep通过命令行使用来搜索包含 Windows 样式换行符的文件。

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

使用 git bash,您可以\r通过以下命令(仅限 bash!)找到包含字符的所有文件:

git grep -Il $'\r'

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

或者替代(它应该适用于所有外壳类型 - 除了 Windows 类型):

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.

这实际上会在您的 shell 中显示为换行符,但只要您将其括在引号中,它就会起作用。

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

最后是 windows CLI(用 CMD 和 PowerShell 测试):

git grep -Il "\r"


Used options

使用的选项

  • -Iexcludes binary files from the match
  • -lshows only the file names with matches, rather than all matches
  • -I从匹配中排除二进制文件
  • -l仅显示匹配的文件名,而不是所有匹配项

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

此外,如果您想限制对多个文件的搜索,您可以使用该--cached选项,该选项只会搜索您在索引中拥有的文件。

You can read the documentationfor more information.

您可以阅读文档以获取更多信息。