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:
git add . git commit -a // added a message git push
I then did the following in the dev directory:
git clone [email protected]: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:
1,3c1,3 < <? < echo '<p>Hello world!</p>'; < ?> --- > <? > echo '<p>Hello world!</p>'; > ?>
Output a "normal" diff, which is the default. Produce output only when files differ. If there are no differences, output nothing. Report when two files are the same.
diff stands for difference. This command is used to display the differences in the files by comparing the files line by line.
diff is a command-line utility that allows you to compare two files line by line. It can also compare the contents of directories. The diff command is most commonly used to create a patch containing the differences between one or more files that can be applied using the patch command.
- Unix & Linux Stack Exchange diff reports two files differ, although they are the same! Bookmark this question. Show activity on this post. I have two files which look identical to me (including trailing whitespaces and newlines) but diff still says they differ.
If exactly one of path1 or path2 is a directory, diff uses a file in that directory with the same name as the other file name. If both are directories, diff compares files with the same file names under the two directories; however, it does not compare files in subdirectories unless you specify the –r option.
My first guess, which turns out to be confirmed, is that the files use different line endings. It could be some other difference in whitespace, such as the presence of trailing whitespace (but you typically wouldn't get that on many lines) or different indentation (tabs vs spaces).
This message appears when diff is comparing the contents of directories, but you have not specified –r . When diff discovers two subdirectories with the same name, it reports that the directories exist, but it does not try to compare the contents of the two directories.
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:
git config --global core.autocrlf true
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With