why `git diff` reports no file change after `git add`

eridal picture eridal · Sep 30, 2014 · Viewed 14.7k times · Source

 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
.
..

Answer

Bhaskar picture Bhaskar · Sep 30, 2014

Please try git diff --staged command.

Alternative options available are listed below.

git diff

shows changes between index/staging and working files. Since, in your case, git add moved your files-with-changes to staging area, there were no modifications shown/seen.

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