我看过所有类似的问题。然而,我又检查了一遍,确实发生了一些奇怪的事情。

在一台服务器上(Solaris with Git 1.8.1),我克隆了Git存储库,然后将. Git文件夹复制到我现有的活动文件中。这很好,我可以跑了

git status

then

git diff [filename]

检查任何不同的文件。

在另一台服务器上(Solaris with Git 1.7.6),我做的完全相同

git diff [filename]

即使文件内容完全不同,也不会显示任何内容。我还测试了添加一个新文件,提交它,然后编辑。同样的问题,git status显示文件已更改,但git diff没有显示任何内容。如果我下载更改后的文件并在本地运行diff,那么我将得到diff输出。


当前回答

我也遇到过类似的问题。git diff文件没有显示任何内容,因为我将文件添加到git索引中,其中部分名称是大写的:GeoJSONContainer.js。

之后,我将其重命名为GeoJsonContainer.js,并停止跟踪更改。git diff GeoJsonContainer.js没有显示任何东西。我必须用强制标志从索引中删除文件,并再次添加文件:

git rm -f GeoJSONContainer.js
git add GeoJSONContainer.js

其他回答

Git diff -a将所有文件视为文本,它为我工作。

简短的回答

运行git add有时会有所帮助。

例子

Git状态显示已更改的文件和Git diff显示什么都没有…

> git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   package.json

no changes added to commit (use "git add" and/or "git commit -a")
> git diff
> 

运行git add可以解决不一致的问题。

> git add
> git status
On branch master
nothing to commit, working directory clean
> 

我遇到了这个问题。我的情况与rcwxok发布的LESS问题类似。

在我的例子中,我将PAGER环境变量设置为PAGER='less -RSF'。

然而,与前面的答案不同,我不想删除-F选项,因为我显式地把它放在那里,希望防止在less中显示差异,如果它少于一个屏幕。

为了得到想要的结果,我没有删除-F,而是添加了-X: PAGER='less -RSFX'。这既解决了git差异的问题,此外,它防止显示短差异与较少。

我怀疑您的Git安装或存储库有问题。

尝试运行:

GIT_TRACE=2 git <command>

看看能不能找到有用的线索。如果这没有帮助,只需使用strace,看看哪里出了问题:

strace git <command>

正如在前面的回答中已经提到的,这种情况可能是由于行结束问题(CR/LF vs. LF)而出现的。我用这个命令解决了这个问题(在Git 2.22.0版本下):

git add --renormalize .

根据手册:

       --renormalize
           Apply the "clean" process freshly to all tracked files to
           forcibly add them again to the index. This is useful after
           changing core.autocrlf configuration or the text attribute in
           order to correct files added with wrong CRLF/LF line endings.
           This option implies -u.