Git 和 IntelliJ 行分隔符问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35503036/
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
Git and IntelliJ lines separator issue
提问by ikos23
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).
我正在IntelliJ 15.0.3
通过 Git Bash 使用 Git(提交和推送更改)。当我fetch
从远程 git 存储库归档时,它包含不同的行分隔符(混合模式或如何调用)。我的意思是有些行CRLF
以LF
(同一个文件)结尾,有些行以(同一个文件)结尾。
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).
当我在 IDEA 中进行更改时 - 文件会自动保存,并且所有行分隔符都减少(更改)为 IDEA 默认行分隔符(LF
对我而言)。
And git treats these changes as changes to the file, as a result I commit file with a lot of changes like these:
并且 git 将这些更改视为对文件的更改,因此我提交了包含大量更改的文件,如下所示:
- some line
+ some line
Because some line [CRLF]
was changed to some line [LF]
.
因为some line [CRLF]
改成了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.
如何配置Git
忽略此或如何配置IntelliJ IDEA
以这种混合模式保留文件?我不想在没有更改时提交更改。
回答by VinayVeluri
While installing git, we will have option to set the checkout as-is and commit as-is
.
在安装 git 时,我们可以选择设置checkout as-is and commit as-is
.
If that is not set, we can do with the git config.
如果没有设置,我们可以使用 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
回答by Vadzim
IDEA delegates changes resolution to git.
IDEA 将更改分辨率委托给 git。
So you would have to either force desired line breaks in IDEAor to force desired line breaks in git.
所以,你将不得不要么在IDEA力所需的换行或强制所需的换行中的git。
In my case autocrlf true
was already present on my PC but the working copy was initially copied from collegue's share where it had been checked out with another setting.
在我的情况下autocrlf true
,我的 PC 上已经存在工作副本,但工作副本最初是从同事的共享中复制的,在那里它已使用其他设置签出。
A clean checkout would resolve the problem but I had some files already changed and wanted to preserve them. This can be worked around by resetting git index for the whole projector just desired subdirectory.
干净的结帐可以解决问题,但我已经更改了一些文件并希望保留它们。这可以通过重置整个项目的git index或只是需要的子目录来解决。