“Inconsistent line ending style” nightmare

99封情书 提交于 2019-12-03 02:55:10

Under Windows 7, you can use Notepad++ v5.6.8 to convert EOL

Edit --> EOL Conversion --> Windows / Unix / Mac

In Notepad++, select " View -> Show Symbol -> Show End of Line"

In the search box (Control-F) select the Regular Expression search mode and search for the string:

[^\r]\n$

(translation: \n without a \r before it).

This will bring you directly the problem line(s) where you'll see the line ending with LF rather than with the pair CR-LF

So I answer my own question with @assylias's answer :

You can capture the w: (\w)\n$ and replace with $1\r\n where $1 is the character.

Searching & replacing with Netbeans with this regex does the job.

Edit : my problem was that a custom script inserted wrong EOL chars (\n instead of \r\n) in these files)

If your line endings are all in order, it could be that your text file has a UTF16 Byte Order Mark (BOM).

You can fix that using Notepad++. Encoding -> Convert to UTF-8.

In Vim or GVim under Windows, the broken files all showed ^M at the end of each line.

To fix it: :s/\r//g to remove the broken extra line endings.

In relation to the post just above, actually the vim regexp should be :1,$s/\r//g. Another way on *n?x is using sed:

sed -i '-es/\r//g'

To solve the problem with different line endings, you can set the SVN property as follows:

svn propset svn:eol-style native my_file

Although this will solve the line endings problems and make merging easier, it will mean that blame will show the person adding the eol-style as the changer of all lines, and it also means that your working files will end up getting copied into temp folder when doing a diff.

The blame issue can be solved afterwards by doing this:

svn blame my_file -x "--ignore-space-change --ignore-eol-style"

What I did was open the project properties window by right-clicking the file explorer while browsing the repo I wanted to edit, then selected:

TortoiseSVN > Properties > New... > EOL > As is (no specific EOL).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!