문제

I have a git repository containing C# code, and I'm running MSysGit on Windows.

core.autocrlf is turned on, and I'm using the .gitattributes from this question, and I "renormalised" my repo as mentioned at the bottom of this Github guide.

Now for some of the .cs files in my repository, if I change even one character, MSysGit thinks the whole file has changed.

I cloned the repository fresh. I tried editing the file first in Visual Studio, but then I tried opening it in SciTE which shows me line ending and tab characters, and also I trust it not to do anything weird to the file (like change the encoding).

So, I clone the repository fresh:

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

I check the repository and the file:

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

I open the file in SciTE (note that the line endings are CRLF and there are no tabs):

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

and change one character (and note that CRLF and no tabs are still true):

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

and now git thinks everything's changed:

$ 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;
...

A normal diff program doesn't think the two files are so different, and git diff on Unix doesn't think they're too different, but msysgit does.

Anyone ever encounter this before or have any ideas?

도움이 되었습니까?

해결책

A few things that can make Git show the entire file as changed:

  • Line endings -- but you said you checked these and they're the same;
  • Indentation -- VS (especially if you have some extensions installed) might change the indentation from tabs to spaces or vice-versa. You can check this with "Show Whitespace" (Ctrl-R, Ctrl-W in VS or the relevant option in your differ).
  • Encoding -- if VS decides to re-encode the file in some different encoding (e.g. UTF16) it might show up as entirely changed although the textual representation would look the same.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top