git ignore line endings

折月煮酒 提交于 2019-12-22 06:37:36

问题


I know that similar questions have been asked, but I still can't get it working.

My project is shared among people using different operating systems, and I'm on OSX. Also, not everyone uses git yet and I end up sometimes having to commit changes of others.

Sometimes, out of nowhere git says there are pending changes. Looking at the files they look identical:

@@ -1,6 +1,6 @@
-<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment"
-        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
->
-    <Deployment.Parts>
-    </Deployment.Parts>
-</Deployment>
+<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+>
+    <Deployment.Parts>
+    </Deployment.Parts>
+</Deployment>

I suspect those are line ending issue.

[edit] One external diff tool specifically says: "status: 1 difference Line endings differ - left: Windows (CRLF), right: Unix (LF)"

Following some of the online tips, my configuration looks like:

[core]
    excludesfile = /Users/nathanh/.gitignore_global
    autocrlf = input
    attributesfile = /Users/nathanh/.config/git/attributes
    whitespace = cr-at-eol

And my attributes file:

# Ignore all differences in line endings
*        -crlf

Why is it still showing me that the files are modified?


回答1:


Read this from JetBrains.com

To have Git solve such problems automatically, you need to set the core.autocrlf attribute to true on Windows and to input on Linux and OS X. For more details on the meaning of the core.autocrlf attribute, see the article Mind the End of Your Line orDealing with Line Endings. You can change the configuration manually by running

git config --global core.autocrlf true 

on Windows or

git config --global core.autocrlf input 

on Linux and OS X. However, IntelliJ IDEA can analyze your configuration, warn you if you are about to commit CRLF into the repository, and offer to set the core.autocrlf setting to true or input depending on the operating system used.

Hopefully this might shed some light on the problem.



来源:https://stackoverflow.com/questions/31653922/git-ignore-line-endings

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