4

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?

Community
  • 1
  • 1
Robin Winslow
  • 10,908
  • 8
  • 62
  • 91

1 Answers1

3

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.
Avish
  • 4,516
  • 19
  • 28
  • My first thought was the line endings, but given that's been checked the next in line will be the tabs/spaces issue for indentations. – ChrisF Oct 29 '12 at 12:14
  • It doesn't seem to be tabs/spaces. How can I check encoding? Although from an earlier experience I had, UTF-16 encoding is treated as binary by git, which my files aren't. – Robin Winslow Oct 29 '12 at 12:22
  • I rewrote the question after some investigation – Robin Winslow Oct 29 '12 at 13:02
  • Try to ask Git's diff to ignore whitespace and see what you get. Alternatively, try to ask another differ to not ignore whitespace and see if you get something different. – Avish Oct 29 '12 at 15:35
  • The problem was fixed when I restarted my computer. *sigh*. – Robin Winslow Nov 08 '12 at 15:07
  • Thanks for this answer. We had the exact same problem, and it turned out to be automatic conversion of tabs to spaces in Visual Studio. – leifericf Jul 19 '13 at 10:59