Git won't diff my main plugin file?
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?
2 Solutions collect form web for “Git won't diff my main plugin file?”
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:
*.c files are text, you can just say:
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:
CTRL+M to get