差异返回完整的文件相同的文件 [英] diff returning entire file for identical files

查看:79
本文介绍了差异返回完整的文件相同的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个拥有git回购的网站。我克隆了repo,这样我就可以在一个目录中开发,然后推送到repo,然后拉入live / prod目录(如果有更好的方法,建议您有兴趣提供这样的建议,但这不在这个问题的范围)。



我在实时目录中执行以下操作来推送所有最新的更改:

  git add。 
git commit -a //添加了一条消息
git push

然后我在开发目录中做了以下工作:

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

然后我打开两个文件,prod / root / test.php和dev / root / test.php,它们看起来完全相同。然而,当我做了下面的diff命令时,它输出了整个文件:

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

我很困惑,为什么diff会输出整个文件,重新相同...我也尝试了谷歌搜索,并找不到任何其他人与这个问题。也许这是一个行结束问题或字符编码问题,他们看起来相同,但他们实际上是不同的,当你推到他们的回购时,git / bitbucket将它转换?这是我能想到的唯一的事情......要么是这样,要么我错过了一些非常明显的东西。



以下是输出:

  1,3c1,3 
< < ;?
< echo'< p> Hello world!< / p>';
< ?>
---
> < ;?
> echo'< p> Hello world!< / p>';
> ?>


解决方案

这似乎是一个空白问题,为了避免他们在将来可以设置Git来规范它们。

Windows和UNIX系统不使用相同的行结束符,以防止基于这些冲突的发生,你应该这样设置你的git配置:
$ b $ ul

  • Windows git config - 全局core.autocrlf true

  • Unix git config --global core.autocrlf input
  • >

      git config --global core.whitespace尾随空格,空格前标签,非标签缩进


    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 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:

    1,3c1,3
    < <?
    < echo '<p>Hello world!</p>';
    < ?>
    ---
    > <?
    > echo '<p>Hello world!</p>';
    > ?>
    

    解决方案

    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
    

    这篇关于差异返回完整的文件相同的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆