git diff
认为没有变化 ..即使git status
将其报告为已修改?
$ 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
但是为了看到差异,我需要显式添加最后一个reversion哈希..
$ 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
.
..
答案 0 :(得分:29)
请尝试git diff --staged
命令。
您可以使用更多选项。
git diff
显示索引/暂存和工作文件之间的更改。在您的情况下,git add
将file-with-changes
放入暂存区域。因此,登台和工作文件之间没有区别。
git diff --staged
显示HEAD和索引/暂存之间的变化。 git diff --cached
也做了同样的事情。 staged
和cached
可以互换使用。
git diff HEAD
显示HEAD和工作文件之间的变化
git diff $commit $commit
显示2次提交之间的更改
git diff origin
显示HEAD和&amp;之间的差异。远程/起源
答案 1 :(得分:5)
git diff
针对索引进行区分,而不是针对HEAD
修订版。通过运行git add
,您已将更改添加到索引中,因此当然没有差异!使用
git diff HEAD
查看您的树状态与HEAD
修订版之间的差异,或git diff --cached
查看您的索引与HEAD
修订版之间的差异。答案 2 :(得分:1)
进入完全相同的问题。
您将看到filename1.c已提交。
答案 3 :(得分:0)
因为默认情况下git diff
会检查暂存区域和工作副本之间的差异。当您git add
时,您的临时区域与您的工作副本相匹配,因此差异报告不会发生任何变化。
添加--cached
标志会告诉diff对HEAD
的差异。