git 忽略行尾
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31653922/
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 ignore line endings
提问by Nathan H
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.
我的项目在使用不同操作系统的人之间共享,我在 OSX 上。此外,并不是每个人都使用 git,我有时最终不得不提交其他人的更改。
Sometimes, out of nowhere git says there are pending changes. Looking at the files they look identical:
有时,git 会突然说有待处理的更改。查看它们看起来相同的文件:
@@ -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)"
[编辑] 一个外部差异工具特别指出:“状态:1 差异行尾不同 - 左:Windows (CRLF),右: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?
为什么它仍然显示文件已被修改?
回答by Hexana
Read this from JetBrains.com
从 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 自动解决此类问题,需要在 Windows 上将 core.autocrlf 属性设置为 true,在 Linux 和 OS X 上输入。有关 core.autocrlf 属性含义的详细信息,请参阅文章Mind the End of您的行或处理行尾。您可以通过运行手动更改配置
git config --global core.autocrlf true
on Windows or
在 Windows 或
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.
在 Linux 和 OS X 上。但是,IntelliJ IDEA 可以分析您的配置,在您将 CRLF 提交到存储库时发出警告,并根据所使用的操作系统提供将 core.autocrlf 设置设置为 true 或输入。
Hopefully this might shed some light on the problem.
希望这可以对这个问题有所了解。