为什么`git diff`在`git add`后报告没有文件改变 [英] why `git diff` reports no file change after `git add`

查看:1263
本文介绍了为什么`git diff`在`git add`后报告没有文件改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 git diff 认为没有变化



..即使 git status 将它们报告为修改

  $ git status 
在分支大师
上您的分支在2次提交之前领先于origin / master。
(使用git push发布你的本地提交)

要提交的变更:
(使用git reset HEAD< file> ...

新文件:文件添加
修改:文件更改<<它知道有变化

但为了看到差异,我需要明确地添加最后的逆转Hash ..
$ b $ pre $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ g $ diff rev- hash
diff --git a / file-with-changes b / file-with-changes
index d251979..a5fff1c 100644
--- a / file-with-changes
+++ b /文件变更

..


解决方案

请尝试 git diff --staged 命令。



您可以使用更多选项。


git diff


显示索引/分段和工作文件之间的变化。在你的情况下, git add file-with-changes 放到暂存区。因此,分段和工作文件没有区别。


git diff --staged


blockquote>

显示HEAD和索引/分段之间的变化。 git diff --cached 也做同样的事情。 staged cached 可以互换使用。


git diff HEAD


显示HEAD和工作文件之间的变化


git diff $ commit $ commit


显示2次提交之间的变化



< blockquote>

git diff origin


显示差异HEAD&远程/原籍


 Why is that git diff thinks there are no changes

..even if git status reports them as modified?

$ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file:   file-added
    modified:   file-with-changes   << it knows there are changes

but in order to see the difference, I need to explicitly add the last reversion hash..

$ git diff
  (nothing)

$ git diff rev-hash
diff --git a/file-with-changes b/file-with-changes
index d251979..a5fff1c 100644
--- a/file-with-changes
+++ b/file-with-changes
.
..

解决方案

Please try git diff --staged command.

More options you can use.

git diff

shows changes between index/staging and working files. In your case, git add put the file-with-changes to staging area. Hence, no difference between staging and working files.

git diff --staged

shows changes between HEAD and index/staging. git diff --cached also does the same thing. staged and cached can be used interchangeably.

git diff HEAD

shows changes between HEAD and working files

git diff $commit $commit

shows changes between 2 commits

git diff origin

shows diff between HEAD & remote/origin

这篇关于为什么`git diff`在`git add`后报告没有文件改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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