diff returning entire file for identical files

I’ve got a website that has a git repo. I cloned the repo so that I could develop in one directory and then push to the repo, and then pull in the live/prod directory (would be interested in suggestions for a better way to do this if there is one, but that’s outside the scope of this question).

I did the following in the live directory to push all my latest changes:

  • How to see the changes in a commit?
  • How can I convert the output of `git diff --color-words` to HTML?
  • GitHub - why two lines are marked as different without any visible differences?
  • Using mercurial and beyond compare 3(bc3) as the diff tool? help needed
  • How do diff/patch work and how safe are they?
  • git diff - handling long lines?
  • git add .
    git commit -a // added a message
    git push

    I then did the following in the dev directory:

    git clone git@bitbucket.org:user/repo.git

    I then opened two files, prod/root/test.php and dev/root/test.php, and they looked identical. However, when I did the following diff command, it outputted the entire file:

    diff prod/root/test.php dev/root/test.php

    I am so confused as to why diff would output the entire file if they’re identical… I also tried googling this and can’t find anyone else with this problem. Maybe it’s a line endings issue or a character encoding issue where they look the same but they are actually different and git/bitbucket converts it when you push to their repo? That’s the only thing I can think of… Either that or I’m missing something really obvious.

    Here’s the output:

    < <?
    < echo '<p>Hello world!</p>';
    < ?>
    > <?
    > echo '<p>Hello world!</p>';
    > ?>

  • Using git, how to do a 'use theirs' during a conflict?
  • How to keep git from tracking all files that end with a “~”?
  • Merge an untracked directory into the tracked directory
  • Git Ignores and Maven targets
  • Git non-cached file being uploaded to Github
  • When I am using Git, should I rebase before I merge?
  • 3 Solutions collect form web for “diff returning entire file for identical files”

    This seems like a whitespace issue, in order to avoid them in the future, you can setup Git to normalize them.

    Windows and UNIX system don’t use same line-ending, to prevent conflict from happening based on these, you should setup you git config this way:

    • Windows : git config --global core.autocrlf true
    • Unix : git config --global core.autocrlf input

    Next, to make sure we only commit with ideal whitespace rules, you can set this config option:

    git config --global core.whitespace trailing-space,space-before-tab,indent-with-non-tab

    Most likely it’s line termination. Try git diff --ignore-space-at-eol. And for plain (not git) diff it’s diff -b.

    That usually means the line endings are different. Most diffin programs allow you to ignore differences in line endings. Does yours allow you to do so?

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