git-Windows + Linux双启动中的CRLF问题 [英] git - CRLF issue in windows + linux dual boot
问题描述
我将用解决问题的解决方案来回答我的问题.
下注者注意事项:我了解在其他各种线程中都讨论了根本原因(这就是我解决问题的方式).这篇文章更多地是关于使用双启动系统如何将您引导到此问题.因此,否,这个问题/答案不是重复的,而是一般问题类别的一个特定实例,从而在此问题上向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:
-
git pull
您在Windows环境中的linux环境中处理过的某些文件,该文件的位置可以从双引导linux环境访问.这会将文件修改为包含CRLF
结尾. - 然后,当您在linux中打开文件时,默认值仅为
LF
,git diff
会说整个文件已修改,因为每个LF
都被更改为CRLF
在每一行. (Atom警告过我,它具有内置的差异计数)
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 containCRLF
endings.- Then when you open up the file in linux, where the default is only
LF
,git diff
will say entire file is modified, because eachLF
got changed toCRLF
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屋!