为什么GitHub认为我的代码有差异? [英] Why does GitHub think my code has differences?

查看:215
本文介绍了为什么GitHub认为我的代码有差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我添加...

# Auto detect text files and perform LF normalization
* text=auto

...到我的配置文件,那么GitHub应用/客户端会说很多(如果不是全部? )存储库中的文件已更改。对于其中的很多人来说,即使它显然没有改变整个文件也是如此。很明显,这是线结束的问题,但我不明白为什么会出现这种情况。

...to my config file then the GitHub app/client says that many (if not all?) of the files in the repository have changed. For many of them it says that the entire file has changed even though it obviously hasn't. Obviously this is an issue with line endings but I don't understand why this is happeneing.

似乎只要告诉Git(通过配置文件)文件类型是文本,然后它会抛出差异。

It seems that as soon as you tell Git (via the config file) that a file type is text then it throws up differences.

推荐答案

使用text = auto,Git希望以LF格式存储文件 - 它不会简单地将过滤器应用于那里。因此,任何尚未使用LF结尾存储的文件将显示为正在修改。您可能想要遵循 gitattributes 手册页中的建议 eol转换部分,并执行以下操作:

With text=auto, Git wants to store the files in LF format--it doesn't simply apply a filter to what is there. As a result, any file that isn't already stored with LF endings will show up as being modified. You probably want to follow the advice on the gitattributes man page in the eol conversion section and do:

$ rm .git/index     # Remove the index to force Git to
$ git reset         # re-scan the working directory
$ git status        # Show files that will be normalized
$ git add -u
$ git add .gitattributes
$ git commit -m "Introduce end-of-line normalization"

这篇关于为什么GitHub认为我的代码有差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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