git应该改变行结尾吗? (在第一行结束时控制+ M或^ M) [英] Should git change the ending of line? (control+M or ^M at the end of the first line)

查看:137
本文介绍了git应该改变行结尾吗? (在第一行结束时控制+ M或^ M)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用git从我的代码从Windows机器。



当其他开发者从他们的liunx机器上的服务器中取出文件,它们在第一行的末尾有 ^ M



如何让git为我照顾这件事?



我的意思是, git 当我(从我的窗口机器)推送服务器上的代码时,code>应该改变行的结尾(在第一行末尾删除控制+ M或^ M)。

解决方案

此GitHub 帮助页面 处理这个非常特定的主题,并通过这些步骤驱动人们正确配置您的Git配置。



基本上,如果您使用的是Mac / Linux,请使用

  $ git config --global core.autocrlf input 



如果你更喜欢Windows的家伙,使用



  $ git config --global core.autocrlf true 



注意:这将在执行结帐或提交时即时转换您的行尾,并确保您文本文件将在您的存储库中包含LF行结尾,同时在工作目录中具有本机行结束符。


$ b 注2 :这将而不是重写存储库的历史记录。现有的提交回执将保留其可能的混合行结尾。



注意3 :确保每个提交者在其下次提交之前执行此配置步骤。

存在另一种方法,它不涉及强制每个人改变其配置。它需要将特定文件名 .gitattributes 添加到您的存储库。有关他在git官方主题中的更多信息 gitattributes文档 。注意4 :githubber的Tim Clem发表了一篇非常详细的博客文章( 介意你的线路结束 )行结尾,相关的配置条目和gitattributes的好处。如果你愿意理解概念,为什么和内部机制,这绝对是必须阅读的。


I use git to pull my code from a windows machine.

When the other developers pull the files from the server on their liunx machine they have the ^M at the end of the first line.

How can make git to take care of this for me?

I mean, git should change the ending of line (delete control+M or ^M at the end of the first line) when I push (from my window machine) the code on the server.

解决方案

This GitHub help page deals with this very specific topic and drives one through the steps to correctly configure your Git configuration.

Basically, if you're working on Mac/Linux, use

$ git config --global core.autocrlf input

If you're rather a Windows guy, use

$ git config --global core.autocrlf true

Note: This will convert your line endings on the fly, while performing a checkout or a commit and ensure that your text files will have LF line endings in your repository while having native line endings in your working directory.

Note 2: This will not rewrite the history of your repository. Existing commits in the repo will keep their potentially mixed lines endings.

Note 3: Ensure that every committer executes this configuration step before their next commit.

An alternative approach, which doesn't involve compelling everyone to change their config, exists. It requires adding a specific file name .gitattributes to your repository. More information about his topic in the git official gitattributes documentation.

Note 4: Tim Clem, a githubber, published a very detailed blog post (Mind the End of Your Line) about line endings, related configuration entries and gitattributes benefits. It's an absolute must read if you're willing to get a good grasp of the concepts, the "why" and the internal machinery.

这篇关于git应该改变行结尾吗? (在第一行结束时控制+ M或^ M)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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