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

在一台服务器上(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输出。


当前回答

对我来说,这与文件权限有关。 在我的项目上使用Mac/Linux的人似乎提交了一些具有非默认权限的文件,我的Windows Git客户端未能重现。

我的解决方案是告诉Git忽略文件权限:

git config core.fileMode false

其他见解:如何让Git忽略文件模式(chmod)的更改?

其他回答

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

我遇到了同样的问题,描述如下: 如果我输入

$ git diff

Git只是返回到提示符,没有任何错误。

如果我输入

$ git diff <filename>

Git只是返回到提示符,没有任何错误。

最后,通过阅读,我注意到git diff实际上调用mingw64\bin\diff.exe来完成这项工作。

是这样的。我正在运行Windows,并安装了另一个Bash实用程序,它改变了我的路径,因此它不再指向我的mingw64\bin目录。

如果你输入:

git diff

它只是返回到提示符,你可能有这个问题。

由git运行的div .exe位于你的mingw64\bin中 目录

最后,为了解决这个问题,我实际上复制了我的mingw64\bin目录到Git正在寻找的位置。我试过了,还是不行。

然后,我关闭我的Git Bash窗口并再次打开它,去到我的同一个存储库,现在它可以工作了。

我有一个类似的问题:git diff会显示差异,但git diff <filename>不会。结果是我将LESS设置为一个包含-F(——quit-if-one-screen)的字符串。移除那面旗帜就解决了问题。

许多其他答案涉及到行尾和核心的差异。autocrlf设置。确实是这样,但我想指出另一个类似的问题:git过滤器。

如果核心。如果selflf =true,那么该行为就像一个git涂抹或清除过滤器,当文本在工作树和索引之间移动时自动处理文本。

类似地,如果你在文件最后一次提交时改变了你的git过滤器设置,它可能会导致git状态的难以捉摸的差异,而这种差异不会在git diff中显示出来。即使git添加了X;git diff——cached——X,取决于配置的过滤器的性质。

This problem happened to me when using nbstripout, a python package that implements git filters that filter out metadata before adding Jupyter notebook files to the index and before diffing them. I resolved it by reverting the filter config settings to how they were before, running git restore on the affected files, and then re-applying the changes to my filter config (because I wanted to keep the new settings long-term). For me, the settings were stored in .git/config under the filter.nbstripout and diff.ipynb sections.

简短的回答

运行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
>