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

在一台服务器上(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只是返回到提示符,没有任何错误。

如果我输入

$ 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窗口并再次打开它,去到我的同一个存储库,现在它可以工作了。

其他回答

正如在前面的回答中已经提到的,这种情况可能是由于行结束问题(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.

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

简短的回答

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

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

我使用git svn,有一个文件有这个问题。对文件的每个祖先使用ls-tree,我注意到其中一个有两个子文件夹——Submit和Submit。由于我使用的是Windows,所以不能同时签出它们,从而导致了这个问题。

解决方案是直接从TortoiseSVN Repo-browser中删除其中一个,然后运行git svn fetch,然后执行git reset——hard origin/trunk。