我尝试使用 CRLF 结尾的行提交文件,但它失败了。
我花了一整天的时间在我的 Windows 计算机上尝试不同的策略,几乎被吸引停止尝试使用 Git 而是尝试 Mercurial 。
请在每个答案中只分享一个最佳实践。
最佳答案
问这个问题将近四年后,我终于
发现 一个完全满足我的答案 !
详见 github:help 的指南
Dealing with line endings。
因此
这是一个 .gitattributes
文件的例子
# Auto detect text files and perform LF normalization
* text=auto
*.cs text diff=csharp
*.java text diff=java
*.html text diff=html
*.css text
*.js text
*.sql text
*.csproj text merge=union
*.sln text merge=union eol=crlf
*.docx diff=astextplain
*.DOCX diff=astextplain
# absolute paths are ok, as are globs
/**/postinst* text eol=lf
# paths that don't start with / are treated relative to the .gitattributes folder
relative/path/*.txt text eol=lf
对于最流行的编程语言,有一个方便的 collection of ready to use .gitattributes files。这对您入门很有用。
创建或调整
.gitattributes
后,您应该执行一劳永逸的 line endings re-normalization 。请注意,在应用程序中打开项目的 Git 存储库后,GitHub Desktop 应用程序可以建议并创建一个
.gitattributes
文件。要尝试此操作,请单击齿轮图标(在右上角)> 存储库设置 ... > 行尾和属性。您将被要求添加推荐的 .gitattributes
,如果您同意,该应用程序还将对您存储库中的所有文件执行规范化。最后是Mind the End of Your Line的文章
提供更多背景知识并解释 Git 是如何演变的
在手头的事情上。我认为这是必读的。
您的团队中可能有一些用户使用 EGit 或 JGit(Eclipse 和 TeamCity 等工具使用它们)来提交他们的更改。那么你就不走运了,正如@gatinueta 在这个答案的评论中所解释的那样:
一个技巧可能是让他们在另一个客户端提交更改,比如 SourceTree 。对于许多用例,我们的团队当时更喜欢该工具而不是 Eclipse 的 EGit。
谁说软件简单? :-/
关于git - Git 的最佳 CRLF(回车、换行)处理策略是什么?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/170961/