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
.
..
git diff
diffs against the index, not against yourHEAD
revision. By runninggit add
, you've put the changes in your index, so of course there are no differences! Usegit diff HEAD
to see the differences between your tree state and theHEAD
revision, orgit diff --cached
to see the differences between your index and theHEAD
revision.Ran into the exact same problem.
You will see that filename1.c got committed.
Please try
git diff --staged
command.More options you can use.
shows changes between index/staging and working files. In your case,
git add
put thefile-with-changes
to staging area. Hence, no difference between staging and working files.shows changes between HEAD and index/staging.
git diff --cached
also does the same thing.staged
andcached
can be used interchangeably.shows changes between HEAD and working files
shows changes between 2 commits
shows diff between HEAD & remote/origin
Because
git diff
by default checks differences between the staging area and your working copy. When yougit add
, your staging area matches your working copy and therefore diff reports no changes.Adding the
--cached
flag tells diff to diff againstHEAD
.