4

我有一个包含 C# 代码的 git 存储库,并且我MSysGit在 Windows 上运行。

core.autocrlf已打开,我正在使用.gitattributesfrom this question ,并且我“重新规范化”了我的 repo,如本 Github 指南底部所述。

现在对于我存储库中的一些.cs文件,如果我更改一个字符,MSysGit则认为整个文件已更改。

我克隆了新的存储库。我首先尝试在 Visual Studio 中编辑文件,然后尝试在SciTE中打开它,它显示了行尾和制表符,而且我相信它不会对文件做任何奇怪的事情(比如更改编码)。

所以,我克隆了新的存储库:

$ git clone git clone git@git.assembla.com:my-repo.v2.git
$ cd my-repo/

我检查存储库和文件:

$ git status
# On branch master
nothing to commit (working directory clean)
$ git diff path/to/myfile.cs
$

我在 SciTE 中打开文件(请注意,行尾是CRLF并且没有制表符):

using System;
using System.Collections.Generic;
...

并更改一个字符(请注意,CRLF没有制表符仍然为真):

using System;
!using System.Collections.Generic;
...

现在 git 认为一切都变了:

$ git diff path/to/myfile.cs
diff --git a/path/to/myfile.cs b/Dpath/to/myfile.cs
--- a/path/to/myfile.cs
+++ b/path/to/myfile.cs
@@ -1,116 +1,116 @@
-<U+FEFF>using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Microsoft.Practices.EnterpriseLibrary.Data;
-using DataModel.Models;
-using DataModel.Mappers.Interfaces;
-using System.Data.Common;
-using System.Data;
...

一个普通的 diff 程序不认为这两个文件有那么大的不同,git diff在 Unix 上也不认为它们有太大的不同,但msysgit确实如此。

有人曾经遇到过这种情况或有任何想法吗?

4

1 回答 1

3

可以使 Git 将整个文件显示为已更改的一些事情:

  • 行尾——但你说你检查了这些,它们是一样的;
  • 缩进——VS(特别是如果你安装了一些扩展)可能会将缩进从制表符更改为空格,反之亦然。您可以使用“显示空白”(VS 中的 Ctrl-R、Ctrl-W 或您不同的相关选项)来检查这一点。
  • 编码——如果 VS 决定以某种不同的编码(例如 UTF16)重新编码文件,它可能会显示为完全改变,尽管文本表示看起来相同。
于 2012-10-29T12:10:31.223 回答