Git-导致伪差异的行尾字符 [英] Git - End of line characters causing fake diffs

查看:116
本文介绍了Git-导致伪差异的行尾字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个git存储库,托管在位存储桶中.我使用源代码树来使用git.我有一个拉取请求,其中某些文件显示为已修改,但文件的内容基本上未更改.我注意到,当我比较位存储桶和源树中​​的两个分支时.这就是那些工具中的差异外观:

I have a git repository which is hosted in bit bucket. I use source tree to work with git. I have a pull request in which some files appear as modified, but the contents of the file are essentially unchanged. I noticed that when I compared the two branches in bit bucket and source tree. This is what the diff looks like in those tools :

-j1
-j2
-j3
+j1
+j2
+j3

这非常令人困惑,因为(1)即使没有真正的更改,它看起来也好像有很多更改,并且(2)如果文件很大,对特定行的任何更改都可能会丢失(不像我上面显示的那个小).

This is very confusing because (1) it makes it appear as though there are many changes, even though there are no real changes, and (2) any changes to a particular line could be missed if you have a huge file (unlike the small one I showed above.)

但是,当我比较命令行(git diff branch1 branch2)中的两个分支时,我发现一个分支中每一行的末尾都有一个^M字符,这是造成差异的原因.

But, when I compared the two branches in command line (git diff branch1 branch2), I saw that there is a ^M character at the end of each line in one branch which is responsible for the difference.

如何确保在git中删除行末字符(如^MTABSPACE等),从而避免混淆请求请求?另外,我如何找出为什么首先要添加这些EOL字符?

How do I ensure that end of line characters like ^M, TAB, SPACE etc. get removed in git so that we can avoid confusion in pull requests ? Also, how do I find out why these EOL characters got added in the first place ?

推荐答案

先尝试

git config --global core.autocrlf false

然后再次克隆,并确保没有差异.
这样可以确保没有自动的" eol转换.

Then clone again, and make sure there is no diff.
That will ensure there is no "automagic" eol conversion.

然后,您可以添加.gitattributes eol指令(此处的示例)

Then you can add in a .gitattributes eol directives (example here)

这篇关于Git-导致伪差异的行尾字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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