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.

  • How to achieve 'pre-checkout' hook in Git/bitbucket?
  • Continuous Integration using GIT / BitBucket on a GIT controlled Intranet
  • How do I setup .git with bitbucket to automatically update live Magento site when pushes are made?
  • Struggling with git, cannot push to remote BitBucket repository
  • Maven JGitFlow plugin authentication for HTTPS
  • git pull hangs after authentication
  • 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?

  • Is it possible to ignore certain directories by default when using git grep?
  • Setting up GIT for Symfony2 project: why add web/bundles folder to gitignore
  • Ignoring certain files in directory even when adding directory with -f
  • git init, add, commit from a different directory
  • Git change working directory
  • Searching for commits which reference a given object
  • 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:

    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

    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)

    Git Baby is a git and github fan, let's start git clone.