git-Windows + Linux双启动中的CRLF问题 [英] git - CRLF issue in windows + linux dual boot

查看:170
本文介绍了git-Windows + Linux双启动中的CRLF问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将用解决问题的解决方案来回答我的问题.

下注者注意事项:我了解在其他各种线程中都讨论了根本原因(这就是我解决问题的方式).这篇文章更多地是关于使用双启动系统如何将您引导到此问题.因此,否,这个问题/答案不是重复的,而是一般问题类别的一个特定实例,从而在此问题上向SO的存储库添加了更多案例.

Note for downvoters: I understand that the root cause is discussed in various other threads (that is how I solved my problem). This post is more about how having a dual boot system can lead you to this issue. So no, this question/answer is not a duplicate, but a particular instance of a general class of problems, adding more cases to SO's repository on this issue.

在家:我使用Linux编写代码. LF用作行尾
在办公室:我在Windows中编写代码. CRLF用作行结尾.
默认情况下,git的autocrlf功能( https://stackoverflow.com/a/20653073/2715083 )让事情开心.

At home: I code in Linux. LF used as line ending
At the office: I code in windows. CRLF used as line endings.
By default, git's autocrlf feature (https://stackoverflow.com/a/20653073/2715083) keeps things happy.

但是,如果您在Linux和Windows上运行双重引导系统,则可以通过以下方式弄乱自己:

However, if you run a dual boot system with Linux and Windows, you can mess yourself up in the following way:

  1. git pull您在Windows环境中的linux环境中处理过的某些文件,该文件的位置可以从双引导linux环境访问.这会将文件修改为包含CRLF结尾.
  2. 然后,当您在linux中打开文件时,默认值仅为LFgit diff会说整个文件已修改,因为每个LF都被更改为CRLF在每一行. (Atom警告过我,它具有内置的差异计数)
  1. git pull some files you worked on in a linux environment in a windows environment, in a location that can be accessed from the dual-booted linux environment. This modifies the files to contain CRLF endings.
  2. Then when you open up the file in linux, where the default is only LF, git diff will say entire file is modified, because each LF got changed to CRLF at every single line. (I was warned by Atom, which has this diff count inbuilt)

推荐答案

您正在谈论text = auto part?我不确定是否需要将其包含在新的.gitattributes文件中,因为当我这样做时, ATOM仍将文件显示为已修改.

you are talking about text=auto part? I wasn't sure If I need to include that in a new .gitattributes file or not, because when I did, ATOM still showed the files as modified.

是的.
要强制Git应用.gitattributes指令,请参阅"

Yes, it does.
To force Git to apply .gitattributes directives, see "Dealing with line endings".

我首先要确保core.autocrlf设置为false.

I would first make sure core.autocrlf is set to false.

git config --global core.autocrlf false

然后:

git add . -u
git commit -m "Saving files before refreshing line endings"

rm .git/index

git reset

git status

git add -u
git add .gitattributes

git commit -m "Normalize all the line endings"

您还可以使用来强制索引重新规范化:

You can also use, to force the index re-normalization:

git rm --cached -r .
git reset --hard

请参见"在git repo和工作副本中强制执行LF eol "

* text=auto eol=lf

这篇关于git-Windows + Linux双启动中的CRLF问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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