Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git won't diff my main plugin file?

Tags:

git

bitbucket

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?

like image 726
Jared Avatar asked Feb 06 '13 15:02

Jared


1 Answers

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

like image 173
robrich Avatar answered Oct 13 '22 12:10

robrich