git 如何在 IntelliJ IDEA 中禁用行分隔符中的差异?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26926888/
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
How can I disable diff in line separators in IntelliJ IDEA?
提问by avfrolov
I'm using Intellij IDEA 14 on Windows and Git as VCS on Unix server.
The line separator in Windows is CLRF (\r\n
) and LF (\n
) in Unix.
In Git, I'm using config --global core.autocrlf input
. This will translate all CRLF's to LF's upon commit.
我在 Windows 上使用 Intellij IDEA 14,在 Unix 服务器上使用 Git 作为 VCS。Windows 中的行分隔符在 Unix 中是 CLRF ( \r\n
) 和 LF ( \n
)。在 Git 中,我使用的是 config --global core.autocrlf input
。这将在提交时将所有 CRLF 转换为 LF。
When I'm using "Reformat code" option on well-formatted file, IDEA marks files as changed and shows diff in line separators only.
当我在格式良好的文件上使用“重新格式化代码”选项时,IDEA 将文件标记为已更改并仅在行分隔符中显示差异。
How can I disable that in IDEA?
如何在 IDEA 中禁用它?
回答by Peter Lawrey
In the bottom right of your window, change [CRLF]
to [LF]
在窗口的右下角,更改[CRLF]
为[LF]
回答by dsaydon
I'm also developing on windows and Because our servers are powered by Linux and all the code has to base on Linux I have preferred to change all my files to LF instead of CRLF.
我也在 Windows 上进行开发,因为我们的服务器由 Linux 提供支持,并且所有代码都必须基于 Linux,所以我更喜欢将所有文件更改为 LF 而不是 CRLF。
from git command line:
从 git 命令行:
git config --global core.autocrlf false
i'm working with intellij idea so it's quite easy:
我正在使用 Intellij 的想法,所以这很容易:
1) File --> settings --> editor --> code style: (for any new file will be created)
a. Scheme : default
b. Line separator: unix and os x (\n)
2) mark the root of the project --> file --> line separator --> LF unix and os x (\n) (for exist files)
1) 文件--> 设置--> 编辑器--> 代码样式:(对于将创建的任何新文件)
一种。方案:默认
湾 行分隔符:unix 和 os x (\n)
2) 标记项目根目录 --> 文件 --> 行分隔符 --> LF unix 和 os x (\n)(用于存在文件)
Remark: you can also use apps like dos2unix.exe or some other scripts.
备注:您也可以使用诸如 dos2unix.exe 之类的应用程序或其他一些脚本。
than I did using my command line: (you can do this also from the idea)
比我使用命令行所做的:(你也可以从这个想法中做到这一点)
git commit -m "bla bla"
git add .
git push origin master
since then, I didn't got those warnings
从那以后,我没有收到这些警告
回答by Roman Gorbatenko
If you came to this thread like me seeking an answer as to why your unit test (JUnit) fails on comparing generated JSON (or any other structure that contains line separators) with one written by hand, you should replace \n by \r\n (for Windows) in your string. The instructions given above don't work for this case.
如果你像我一样来到这个线程寻求答案,为什么你的单元测试 (JUnit) 在比较生成的 JSON(或任何其他包含行分隔符的结构)与手工编写的比较时失败,你应该用 \r\ 替换 \n n (对于 Windows)在你的字符串中。上面给出的说明不适用于这种情况。
UPD.
更新。
回答by Hubert Schumacher
In Intellij 17.3, you can select in the "Compare by" combobox in the compare window whether you want to compare 'Binary content' or 'Text'. In the second case CRLF and LF are not shown as "different".
在 Intellij 17.3 中,您可以在比较窗口的“比较依据”组合框中选择是要比较“二进制内容”还是“文本”。在第二种情况下,CRLF 和 LF 未显示为“不同”。
回答by Alex
Create parser.py in the same dir. Change the name and run. Enjoy))
在同一个目录中创建 parser.py。更改名称并运行。享受))
with open('./file_to_fix.py', 'r') as f:
a = f.read()
with open('./file_to_fix.py', 'w') as f:
# for i in a.split('\r\n'):
# f.write(i)
aa = a.replace('\r\n', '\n')
f.write(aa)