Git - 一些文件被标记为已更改,但“git diff”不显示任何内容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6050836/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:30:11  来源:igfitidea点击:

Git - some files are marked as changed but 'git diff' doesn't show anything

git

提问by dan

I am quite new to Git, thus maybe I am missing something here.

我对 Git 很陌生,因此也许我在这里遗漏了一些东西。

dan@one:/var/www/$ git status -s
M  GoogleChromeExtension.js
M  ApiClient.js

So clearly 2 files have been changed.
But when I run:

所以很明显 2 个文件已被更改。
但是当我运行时:

git diff

no output is shown. I was expecting to get the changes between my working copy and the latest commit.

没有显示输出。我期待在我的工作副本和最新提交之间进行更改。

I am sure yesterday everything was working as expecting...

我相信昨天一切都按预期工作......

Is it maybe because I haven't been pushing the changes to the remote server?

是不是因为我没有将更改推送到远程服务器?

P.S.: I am using GitHub

PS:我正在使用 GitHub

Thanks,
Dan

谢谢,

回答by manojlds

Do a git diff --cached- it compares the HEAD and index, ie stuff added for commit.

做一个git diff --cached- 它比较 HEAD 和索引,即为提交添加的东西。

Just a git diffis between index and working directory, so if all the changes have been staged for commit, you won' see anything in git diff

git diff索引和工作目录之间只有一个,所以如果所有更改都已提交提交,您将不会看到任何内容git diff

The third form is git diff <commit>which compares working directory and commit. So doing git diff HEADwill also give you the diff that you want as well.

第三种形式是git diff <commit>比较工作目录和提交。这样做git diff HEAD也会给你你想要的差异。

回答by Seth Robertson

Depending on exactly what is going on, there may be two solutions to this. It would be best if you didn't use short mode since it hides information important for debugging this.

根据具体情况,可能有两种解决方案。最好不要使用短模式,因为它隐藏了对调试很重要的信息。

If you expect changes, try running git diff HEADto compare the working directory to the last commit. If you have already git added the changes, the default git diff action will be to not show those differences. See the http://git-scm.com/docs/git-diffman page DESCRIPTION which talks about this. The git statusoutput (without -s) would help everyone see whether this was the case.

如果您期望更改,请尝试运行git diff HEAD以将工作目录与上次提交进行比较。如果您已经git add编辑了更改,默认的 git diff 操作将不显示这些差异。请参阅讨论此问题的http://git-scm.com/docs/git-diff手册页描述。该git status输出(无s)表示,将帮助大家看看这是否是这种情况。

Alternately, if you didn't expect changes, this could be an OS/filesystem problem. Please report your OS and filesystem information.

或者,如果您没有预料到更改,这可能是操作系统/文件系统问题。请报告您的操作系统和文件系统信息。

回答by kenorb

Make sure that you're not actually within another git repository. And if for some reason above commands fails, try to run:

确保您实际上不在另一个 git 存储库中。如果由于某种原因上述命令失败,请尝试运行:

git show HEAD

回答by Jay Dubya

I just recently had this problem, and found it happened because I changed my .gitattributes file for the repository. Have you changed any of your .gitattributes files recently? Are all the files that are changed of the same type? My recent issues affected *.sql files, for example. When I undid the change to .gitattributes, the source files became unchanged again.

我最近刚遇到这个问题,发现它发生是因为我更改了存储库的 .gitattributes 文件。您最近是否更改了任何 .gitattributes 文件?更改的所有文件是否属于同一类型?例如,我最近的问题影响了 *.sql 文件。当我撤消对 .gitattributes 的更改时,源文件再次变得不变。

回答by Sujith S

use --no-pager flag with diff

将 --no-pager 标志与 diff 一起使用

git --no-pager diff filepath/filename.extn

回答by siasalar

git diff doesn't show the difference between last two commits. git diff shows difference between last commit and the changes you have done to your code.

git diff 不显示最后两次提交之间的差异。git diff 显示上次提交与您对代码所做的更改之间的差异。