6

So I'm coming across quite an odd problem. No matter what change I make to a certain file, it always says there's 1 deletion and 1 insertion, which is the entire code of the file for each. This doesn't happen to the other files. This only started happening recently and I'm not sure what could have caused it. Any ideas?

I will explain further if you need me to.

Edit: I think I'm getting a little closer to figuring it out. If I type git diff, I get something like this:

<?php^M^M/*^MPlugin Name: SomeName^MPlugin URI: http://...

So yeah it definitely has something to do with line endings, but how can I get rid of those?

Jared
  • 2,006
  • 4
  • 23
  • 43
  • 5
    This sounds like an EOL issue. What line endings are used in the file and which OS are you doing this on? – Nevik Rehnel Feb 06 '13 at 15:39
  • Is git not seeing the newlines properly? Is it considering the file to be a single line? – Mike B Feb 06 '13 at 15:40
  • I'm on Windows 7 using PHPStorm IDE. My client told me when he tried downloading the file it made it all one line. Not sure about the line endings... – Jared Feb 06 '13 at 15:52
  • 2
    Sounds like the file is currently using linux line endings (LF). Maybe your IDE is/was auto converting line endings? – knittl Feb 06 '13 at 16:17
  • It's odd because it's only happening to one file, which happens to be the main file in my plugin. – Jared Feb 06 '13 at 16:24
  • IS there any `.gitattributes` file with a `core.eol` directive in it? – VonC Feb 06 '13 at 18:50
  • Nope, there's no `.gitattributes` file. – Jared Feb 06 '13 at 19:40

2 Answers2

3

Git tries to figure out if a file is text or binary, but sometimes it gets the wrong answer. Why? Hard to say without seeing the file. Maybe you have a non-ascii character in it, maybe line endings are weird, maybe it got confused. Either way, when it gets it wrong, time to break out a .gitattributes file to avoid the confusion.

If the "main" file in question was named myfile.c then you'd create a .gitattributes file like this:

myfile.c text

If all *.c files are text, you can just say:

*.c text

See http://git-scm.com/book/ch7-2.html and Why does Git treat this text file as a binary file? and http://git-scm.com/docs/gitattributes

Community
  • 1
  • 1
robrich
  • 13,017
  • 7
  • 36
  • 63
2

Well it turns out it had nothing to do with any settings in git but with the file. I found this answer over at SE that fixed it by opening the file in VIM and entering this command:

:%s/^M/\r/g (press CTRL+V then CTRL+M to get ^M)

Community
  • 1
  • 1
Jared
  • 2,006
  • 4
  • 23
  • 43