处理行以GIT结尾 [英] Handeling line ending in GIT

查看:142
本文介绍了处理行以GIT结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有10个开发人员团队.他们一半使用Windows,一半使用Linux.他们都在一个项目上一起工作,使用GIT共享工作. CRLF/LF的问题开始...

Let's say we have team of 10 developers. Half of them use Windows and half Linux. All of them work together on a project, sharing work using GIT. Problem with CRLF/LF begins ...

示例:一位使用Window的开发人员与使用Linux的开发人员一起从事同一工作.他们两个都需要查看/编辑相同的文件.

Exmaple: One developer with Window works on the same thing together with developer which is using Linux. Both of them need to view/edit the same files.

CRLF和LF会出现问题吗? GIT处理此问题的方式是什么? (不是强制解决方案)

Will there be problem with CRLF and LF ? What are the ways GIT would handle this problem ? (force Linux isn't solution)

推荐答案

最近的文章" Edward Thomson 的nofollow noreferrer>适用于Windows的Git:行结尾" (以前是GitHubber,现在是Microsoft,现在...再次是rrrr GitHubber)

You can see more with the recent article "Git for Windows: Line Endings" from Edward Thomson (Ex-GitHubber, now Microsoft, now... errr GitHubber again)

处理行尾的关键是使用.gitattributes 来确保将配置提交到存储库.对于大多数人来说,这就像在存储库的根目录下创建一个名为.gitattributes的文件一样简单,该文件包含一行:

The key to dealing with line endings is to make sure your configuration is committed to the repository, using .gitattributes. For most people, this is as simple as creating a file named .gitattributes at the root of your repository that contains one line:

* text=auto

通过此设置,Windows用户将文本文件添加到存储库后,将从Windows样式行结尾(\ r \ n)转换为Unix样式行结尾(\ n).

With this set, Windows users will have text files converted from Windows style line endings (\r\n) to Unix style line endings (\n) when they’re added to the repository.

最初,Windows的Git引入了另一种行尾结尾方法:core.autocrlf.这是一种类似于属性机制的方法:想法是Windows用户将设置Git配置选项core.autocrlf=true,并且在将文件添加到存储库时,其行尾将转换为Unix样式的行尾.

Originally, Git for Windows introduced a different approach for line endings that you may have seen: core.autocrlf. This is a similar approach to the attributes mechanism: the idea is that a Windows user will set a Git configuration option core.autocrlf=true and their line endings will be converted to Unix style line endings when they add files to the repository.

这两个选项之间的区别是微妙的,但很关键:.gitattributes是在存储库中设置的,因此它与所有人共享.但是core.autocrlf是在本地Git配置中设置的.这意味着每个人都必须记住要进行设置,并进行相同的设置.

The difference between these two options is subtle, but critical: the .gitattributes is set in the repository, so its shared with everybody. But core.autocrlf is set in the local Git configuration. That means that everybody has to remember to set it, and set it identically.

我要补充一点,core.autocrlf适用于所有文件,包括二进制文件,而.gitattribure core.eol伪指令可以为特定文件设置(例如*.cpp)

I would add that core.autocrlf applies to all files including binaries ones, whereas .gitattribure core.eol directive can be set for specific files (like *.cpp for instance)

我有始终建议使用.gitattributes方法.

这篇关于处理行以GIT结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆