当在.gitattributes中将EOL设置为CRLF时,Git diff会认为行尾是LF [英] Git diff thinks line endings are LF when EOL is set to CRLF in .gitattributes
问题描述
当我使用Windows行结尾恢复对文件的更改并且.gitattributes将EOL定义为CRLF时,即使十六进制编辑器显示CRLF,git也认为行结束已更改为LR。
仅当.gitattributes定义EOL字符时才会发生。
没有.gitattributes:
这是正确的。
这是我的文件Web.config的原始版本。最后两个字符是 0d 0a(CR LF)
:
00000000:efbb bf3c 3f78 6d6c 2076 6572 7369 6f6e ...<?xml version
00000010:3d22 312e 3022 2065 6e63 6f64 696e 673d =1.0encoding =
00000020: 2275 7466 2d38 223f 3e0d 0autf-8?> ..
我添加一个空格字符到第一行的结尾, 20 0d 0a
:
00000000:efbb bf3c 3f78 6d6c 2076 6572 7369 6f6e ...<?xml version
00000010:3d22 312e 3022 2065 6e63 6f64 696e 673d =1.0encoding =
00000020: 2275 7466 2d38 223f 3e20 0d0autf-8?> ..
Git diff显示空格字符:
diff --git a / Web.config b / Web.config
index bc3c3c3..6215f5e 100644
--- a / Web.config
+++ b / Web.config
@@ -1,4 +1,4 @@
< U + FEFF><?xml version =1.0encoding =utf- 8?> {+ +}
恢复文件和所有更改都不复存在:
$ git checkout Web.config
$ git status Web.config
在分支上开发
您的分支与原产地/开发保持同步。
没有提交,工作目录干净
使用.gitattributes b
*。config eol = crlf
将空格字符添加到第一行的末尾:
00000000: efbb bf3c 3f78 6d6c 2076 6572 7369 6f6e ...<?xml version
00000010:3d22 312e 3022 2065 6e63 6f64 696e 673d =1.0encoding =
00000020:2275 7466 2d38 223f 3e20 0d0autf -8\" >?; ..
Git diff显示空格,但缺少CR(^ M):
diff --git a / Web.config b / Web.config
索引bc3c3c3..9d3bc53 100644
- - a / Web.config
+++ b / Web.config
@@ -1,248 +1,248 @@
< U + FEFF><?xml version =1.0 encoding =utf-8?> [ - ^ M - ] {+ +}
file:
$ git checkout Web.config
$ git status Web.config
在分支上开发
您的分支与origin / develop保持同步。
没有为commit提交更改:
(使用git add< file> ...更新将提交的内容)
(使用git checkout - < ; file> ...放弃工作目录中的更改)
修改:Web.config
没有更改添加到提交(使用git add和/或 git commit -a)
Git认为CR已从所有行中删除:
$ git diff --word-diff-regex =。 Web.config
diff --git a / Web.config b / Web.config
index bc3c3c3..094d1d5 100644
--- a / Web.config
+++ b / Web.config
@@ -1,248 +1,248 @@
< U + FEFF><?xml version =1.0encoding =utf-8?> [ - ^ M - ]
<! - [ - ^ M-]
有关如何配置ASP.NET应用程序的更多信息,请访问[ - ^ M-]
http:// go.microsoft.com/fwlink/?LinkId=152368 [-^M-]
- > [ - ^ M-]
<配置> [ - ^ M-]
但是在十六进制编辑器中并非如此:
00000000:efbb bf3c 3f78 6d6c 2076 6572 7369 6f6e ...<?xml version
00000010:3d22 312e 3022 2065 6e63 6f64 696e 673d =1.0encoding =
00000020:2275 7466 2d38 223f 3e0d 0a3c 212d 2d0dutf-8?> ..<! - 。
00000030:0a20 2046 6f72 206d 6f72 6520 696e 666f。欲了解更多信息
00000040:726d 6174 696f 6e20 6f6e 2068 6f77 2074 ristics on t
00000050:6f20 636f 6e66 6967 7572 6520 796f 7572 o配置您的
00000060:2041 5350 2e4e 4554 2061 7070 6c69 6361 ASP.NET应用程序
00000070:7469 6f6e 2c20 706c 6561 7365 2076 6973重要信息,请访问
00000080:6974 0d0a 2020 6874 7470 3a2f 2f67 6f2e it .. http:// go。
00000090:6d69 6372 6f73 6f66 742e 636f 6d2f 6677 microsoft.com/fw
000000a0:6c69 6e6b 2f3f 4c69 6e6b 4964 3d31 3532 link /?LinkId = 152
000000b0:3336 380d 0a20 202d 2d3e 0d0a 3c63 6f6e 368 ... - > ..< con
000000c0:6669 6775 7261 7469 6f6e 3e0d 0a20 203c figuration> ..<
这里发生了什么,如何让它正常工作?
这是我在某些时候面临的bug。您可以将它报告给 git
团队:
Git的问题或评论可以使用电子邮件地址git@vger.kernel.org将社区发送到邮件列表。错误报告的git应该发送到这个邮件列表。
如果您位于 Windows
您也可以尝试打开关于以下内容的错误报告:
可能是这个bug在最新版本的git 2.10.2 上修复,你可以更新你的最新发布,如果尚未发布:
When I revert changes to a file with Windows line endings and .gitattributes defines the EOL as CRLF, git thinks the line endings have changed to LR, even though a hex editor shows CRLF.
This only happens when .gitattributes defines the EOL character.
Without .gitattributes:
This works correctly.
This is the original version of my file Web.config. The last two characters are 0d 0a (CR LF)
:
00000000: efbb bf3c 3f78 6d6c 2076 6572 7369 6f6e ...<?xml version
00000010: 3d22 312e 3022 2065 6e63 6f64 696e 673d ="1.0" encoding=
00000020: 2275 7466 2d38 223f 3e0d 0a "utf-8"?>..
I add a space character to the end of the first line, 20 0d 0a
:
00000000: efbb bf3c 3f78 6d6c 2076 6572 7369 6f6e ...<?xml version
00000010: 3d22 312e 3022 2065 6e63 6f64 696e 673d ="1.0" encoding=
00000020: 2275 7466 2d38 223f 3e20 0d0a "utf-8"?> ..
Git diff shows the space character:
diff --git a/Web.config b/Web.config
index bc3c3c3..6215f5e 100644
--- a/Web.config
+++ b/Web.config
@@ -1,4 +1,4 @@
<U+FEFF><?xml version="1.0" encoding="utf-8"?>{+ +}
Revert file and all changes are gone:
$ git checkout Web.config
$ git status Web.config
On branch develop
Your branch is up-to-date with 'origin/develop'.
nothing to commit, working directory clean
With .gitattributes
This does not work correctly.
Define CRLF to .gitattributes:
*.config eol=crlf
Add the space character to the end of the first line:
00000000: efbb bf3c 3f78 6d6c 2076 6572 7369 6f6e ...<?xml version
00000010: 3d22 312e 3022 2065 6e63 6f64 696e 673d ="1.0" encoding=
00000020: 2275 7466 2d38 223f 3e20 0d0a "utf-8"?> ..
Git diff shows the space, but the CR is missing (^M):
diff --git a/Web.config b/Web.config
index bc3c3c3..9d3bc53 100644
--- a/Web.config
+++ b/Web.config
@@ -1,248 +1,248 @@
<U+FEFF><?xml version="1.0" encoding="utf-8"?>[-^M-]{+ +}
Revert file:
$ git checkout Web.config
$ git status Web.config
On branch develop
Your branch is up-to-date with 'origin/develop'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: Web.config
no changes added to commit (use "git add" and/or "git commit -a")
Git thinks the CR has been removed from ALL lines:
$ git diff --word-diff-regex=. Web.config
diff --git a/Web.config b/Web.config
index bc3c3c3..094d1d5 100644
--- a/Web.config
+++ b/Web.config
@@ -1,248 +1,248 @@
<U+FEFF><?xml version="1.0" encoding="utf-8"?>[-^M-]
<!--[-^M-]
For more information on how to configure your ASP.NET application, please visit[-^M-]
http://go.microsoft.com/fwlink/?LinkId=152368[-^M-]
-->[-^M-]
<configuration>[-^M-]
But this is not the case in the hex editor:
00000000: efbb bf3c 3f78 6d6c 2076 6572 7369 6f6e ...<?xml version
00000010: 3d22 312e 3022 2065 6e63 6f64 696e 673d ="1.0" encoding=
00000020: 2275 7466 2d38 223f 3e0d 0a3c 212d 2d0d "utf-8"?>..<!--.
00000030: 0a20 2046 6f72 206d 6f72 6520 696e 666f . For more info
00000040: 726d 6174 696f 6e20 6f6e 2068 6f77 2074 rmation on how t
00000050: 6f20 636f 6e66 6967 7572 6520 796f 7572 o configure your
00000060: 2041 5350 2e4e 4554 2061 7070 6c69 6361 ASP.NET applica
00000070: 7469 6f6e 2c20 706c 6561 7365 2076 6973 tion, please vis
00000080: 6974 0d0a 2020 6874 7470 3a2f 2f67 6f2e it.. http://go.
00000090: 6d69 6372 6f73 6f66 742e 636f 6d2f 6677 microsoft.com/fw
000000a0: 6c69 6e6b 2f3f 4c69 6e6b 4964 3d31 3532 link/?LinkId=152
000000b0: 3336 380d 0a20 202d 2d3e 0d0a 3c63 6f6e 368.. -->..<con
000000c0: 6669 6775 7261 7469 6f6e 3e0d 0a20 203c figuration>.. <
What is going on here and how do I get it to work correctly?
This is a bug on git I faced some times. You may report it to the git
team:
Questions or comments for the Git community can be sent to the mailing list by using the email address git@vger.kernel.org. Bug reports for git should be sent to this mailing list.
If you are on Windows
you could also try to open a bug report on:
May be this bug is fixed on the latest version of git 2.10.2
, you could to update yours to the latest released, if is not already:
这篇关于当在.gitattributes中将EOL设置为CRLF时,Git diff会认为行尾是LF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!