Git和IntelliJ行分隔符问题 [英] Git and IntelliJ lines separator issue
问题描述
我在 IntelliJ 15.0.3
中工作,并通过Git Bash使用Git(提交和推送更改)。当我从远程git存储库
获取 fetch
文件时,它包含不同的行分隔符(混合模式或其调用方式)。我的意思是有些行以 CRLF
结尾,有些行以 LF
结尾(同一个文件)。
当我在IDEA中进行更改时,会自动保存文件,并将所有行分隔符缩小(更改)为IDEA默认行分隔符( LF
为我)。
和git将这些更改视为文件的更改,因此我提交了许多像这些更改的文件:
- 某行
+某行
由于某行[CRLF]
已更改为某行[LF]
。
如何配置 Git
来忽略这个或如何配置 IntelliJ IDEA
在这种混合模式下保留文件?我不想在没有更改时提交更改。
在安装git时,我们可以选择按原样设置结帐并按原样提交
。
如果没有设置,我们可以使用git config 。
以下命令可帮助您完成此操作。
git config --global core.autocrlf true
根据文档:
Git可以通过将CRLF行尾自动转换为LF当
将一个文件添加到索引时,反之亦然,当它将代码签出到
文件系统中时。您可以使用core.autocrlf设置打开此功能。
如果你在Windows机器上,将它设置为true - 这将LF结尾转换为
I am working in IntelliJ 15.0.3
and using Git through Git Bash (to commit and push changes). When I fetch
file from remote git repository
it contains different line separators (mixed mode or how it's called). I mean that some lines ends with CRLF
and some lines ends with LF
(the same file).
When I make change in IDEA - file is automatically saved and all line separators are reduced (changed) to IDEA default line separator (LF
for me).
And git treats these changes as changes to the file, as a result I commit file with a lot of changes like these:
- some line
+ some line
Because some line [CRLF]
was changed to some line [LF]
.
How to configure Git
to ignore this or how to configure IntelliJ IDEA
to leave file in this mix-mode? I don't want to commit changes when there are no changes.
While installing git, we will have option to set the checkout as-is and commit as-is
.
If that is not set, we can do with the git config.
Following command helps you in doing so.
git config --global core.autocrlf true
As per documentation:
Git can handle this by auto-converting CRLF line endings into LF when you
add a file to the index, and vice versa when it checks out code onto your
filesystem. You can turn on this functionality with the core.autocrlf setting.
If you’re on a Windows machine, set it to true – this converts LF endings into
这篇关于Git和IntelliJ行分隔符问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!