git diff 返回相同文件的整个文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12876350/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
diff returning entire file for identical files
提问by Andrew Rasmussen
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).
我有一个有 git repo 的网站。我克隆了 repo,这样我就可以在一个目录中开发,然后推送到 repo,然后拉入 live/prod 目录(如果有更好的方法,我会感兴趣,但那不在这个问题的范围)。
I did the following in the live directory to push all my latest changes:
我在 live 目录中执行了以下操作以推送所有最新更改:
git add .
git commit -a // added a message
git push
I then did the following in the dev directory:
然后我在 dev 目录中执行了以下操作:
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:
然后我打开了两个文件,prod/root/test.php 和 dev/root/test.php,它们看起来完全一样。但是,当我执行以下 diff 命令时,它输出了整个文件:
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.
我很困惑为什么如果它们相同,为什么 diff 会输出整个文件......我也尝试过谷歌搜索,但找不到其他人有这个问题。也许这是行尾问题或字符编码问题,它们看起来相同但实际上不同,当您推送到他们的存储库时,git/bitbucket 会对其进行转换?这是我唯一能想到的......要么是那样,要么我错过了一些非常明显的东西。
Here's the output:
这是输出:
1,3c1,3
< <?
< echo '<p>Hello world!</p>';
< ?>
---
> <?
> echo '<p>Hello world!</p>';
> ?>
回答by Simon Boudrias
This seems like a whitespace issue, in order to avoid them in the future, you can setup Git to normalize them.
这似乎是一个空格问题,为了将来避免它们,您可以设置 Git 来规范化它们。
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 和 UNIX 系统不使用相同的行尾,为了防止基于这些发生冲突,你应该这样设置你的 git config:
- Windows:
git config --global core.autocrlf true
- Unix:
git config --global core.autocrlf input
- 窗户:
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
回答by Michael Krelin - hacker
Most likely it's line termination. Try git diff --ignore-space-at-eol
. And for plain (not git
) diff it's diff -b
.
很可能是线路终止。试试git diff --ignore-space-at-eol
。对于普通(非git
)差异,它是diff -b
.
回答by Patrick
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?
这通常意味着行尾不同。大多数差异程序允许您忽略行尾的差异。你的允许你这样做吗?