MAC WINDOWS LINUX ALL
If you develop in a cave, on a single platform, and don't share your code with anyone then you can happily move on and not worry about line endings because the default settings in Git will suit you just fine. The rest of you, read on!
Global setting
Git will automatically manage line endings for you if you set the core.autocrlf option. On Windows, you usually want to use true for this setting.
$ git config --global core.autocrlf true
Per-repo settings
Git allows you to set the line ending properties for a repo directly using the text attribute in the .gitattributes file. This file is committed into the repo and overrides the core.autocrlf setting, allowing you to ensure consistant behaviour for all users regardless of their git settings.
The .gitattributes file should be created in the root of the repository and committed into the repo like any other file.
text=auto
This setting will tell git to handle the files specified automatically. This is a good default option.
text
This setting tells git to always normalize the files specified. When committed they are stored with LF, on checkout they are converted to the OS's native line endings.
text eol=crlf
This setting tells git to normalize the files specified on commit, and always convert them to CRLF on checkout. You should use this for files that must retain CRLF endings, even on OSX or Linux.
text eol=lf
This setting tells git to normalize the files specified on commit, and always convert them to LF on checkout. You should use this for files that must retain LF endings, even on Windows.
binary
This setting tells git that the files specified are not text at all, and it should not try to change them. The binary setting is an alias for -text -diff.
Example
Here's an example .gitattributes file, you can use it as a template for all your repos:
# Set default behaviour, in case users don't have core.autocrlf set.
* text=auto
# Explicitly declare text files we want to always be normalized and converted
# to native line endings on checkout.
*.c text
*.h text
# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf
# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
The advantage of this is that your end of line configuration now travels with your repository and you don't need to worry about whether or not collaborators have the proper global settings.
Re-normalizing a repo
After you've set the core.autocrlf option and created a .gitattributes file, you may find that git wants to commit files that you've not modified. This is because git wants to normalize the line endings for you. The best way to do this is wipe out your working tree (all the files except the .git directory) and then restore them. Make sure you've committed any work before you do this, or it will be lost.
git rm --cached -r .
# Remove everything from the index.
git reset --hard
# Write both the index and working directory from git's database.
git add .
# Prepare to make a commit by staging all the files that will get normalized.
# This is your chance to inspect which files were never normalized. You should
# get lots of messages like: "warning: CRLF will be replaced by LF in file."
git commit -m "Normalize line endings"
# Commit
Thanks to Charles Bailey's post on stack overflow for the basis this solution.
分享到:
相关推荐
这篇PPT课件是针对八年级英语教学的内容,主题为“应对困难”(Dealing with trouble)。通过一系列的填空练习和情景模拟,旨在帮助学生掌握如何在不同情况下正确处理问题,尤其是面对紧急情况时的应对策略。以下是...
在进行数据包络分析(Data Envelopment Analysis, DEA)研究时,经常需要面对的问题之一是如何处理非期望产出(undesirable outputs)。传统DEA模型在处理生产效率分析时通常假设决策单元(Decision Making Units, ...
《图像处理:处理纹理》是图像处理领域内一部权威性的著作,由Maria Petrou和Pedro Garcia Sevilla两位学者共同编写,他们分别来自英国伦敦帝国理工学院和西班牙卡斯特利翁的Jaume I大学。该书由全球知名的学术出版...
R scripts for dealing with mturk
"Dealing With Stress" 这个主题的工作坊就是为此而设,旨在帮助参与者理解和管理他们面临的压力。 首先,我们要理解压力的来源。在大学生活中,学生面临的主要压力源包括: 1. **学术压力**:大学课程繁重,报告...
Chapter 3 Dealing with trouble测试题2.doc
"Dealing with Hard People"这一主题,虽然看似不直接涉及技术,但它实际上对提升工作效率和团队协作至关重要。在这个知识领域,我们将深入探讨如何在复杂的职场环境中处理人际关系,特别是那些难缠的人物。 首先,...
- - 与人交往中注意的一些容易被跳过的细节.以及基础理论分析与人交往出现的情况.
音频地环回问题详解 音频地环回是音频系统中常见的问题,主要由于不同设备通过不同的路径连接到共同的地线而产生。这种多路径接地方式实际上就像一个天线,会拾取并引入干扰。当地环回发生时,地线(通常是屏蔽层)...
这篇PPT学习教案是针对八年级英语的一课,主题为"Dealing with trouble",旨在帮助学生学习如何处理各种突发状况。以下是对其中涉及的知识点的详细解释: 1. **词汇与短语**: - **hurry**:匆忙,表示动作迅速。 ...
处理不均衡数据_(深度学习)!_Dealing_with_imbalanced_data_(deep_learning)
标题中的"ASTM E178 - 21"指的是美国材料与...通过阅读提供的"ASTM E178 - 21 Standard Practice for Dealing With Outlying Observations - 完整英文版(11页).pdf"文件,可以深入学习这一标准的细节和具体实施步骤。
在Microsoft Foundation Class (MFC)库中,"MFC dealing with window size_IntheFrame_MFC实例_" 主题涉及如何在框架窗口(Frame Window)中管理子窗口(Subwindow)的大小。MFC是C++的一个类库,它为Windows应用...
### 多标签分类:通过合并标签处理不平衡问题 #### 摘要与介绍 本文讨论了一个在多标签分类(Multi-Label Classification, MLC)领域中的常见问题——数据不平衡,并提出了一种新颖的方法来解决这一难题。...
A chapter on several sorting algorithmsFunctions (planar and solid) with many interesting examplesOrdinary differential equationsAdvantages of Mathematica® dealing with the Pi numberThe power of ...
There are chapters dealing with all the important aspects of the Android platform, including GUI design, file- and data-handling, coping with phone calls, multimedia apps, interaction with location ...
标题中的"071431_VB_picture_dealing_with.rar_vb matlab"指的是一个关于VB(Visual Basic)和MATLAB结合使用的图像处理压缩包。这个压缩包可能包含了一系列的VB代码和MATLAB脚本,用于图像的导入、处理和分析。 在...
标题与描述中提到的知识点主要围绕在iOS应用开发中如何处理数据、用户默认设置(User Defaults)、SQLite数据库以及网络服务(Web Services)。以下是对这些关键概念的深入解析: ### 处理iOS应用中的数据 ...
# 处理视觉里程计(VO)中的结构化场景:不完整SURF方法 ## 摘要 本文探讨了在结构化环境中处理视觉里程计(VO)的问题。当前常用的特征提取方法,如Harris角点检测、SURF、ORB等,在大多数情况下表现良好,但在...
Chapter 7 Dealing With Huge Data Files Chapter 8 Working With A Mountain Of Data Chapter 9 Practical Data Analysis Chapter 10 Browser-Based Visualization Chapter 11 Server-Side Visualization Chapter ...