'git diff' 的简写是什么?

What is 'git diff' short-hand for, if anything?

如果我修改文件并执行 git diff 我会在终端中看到差异。

如果我然后暂存修改后的文件并再次执行 git diff,则没有差异。如果我改为 git diff HEAD 我会在终端中看到差异,就像在暂存之前一样。

那么 git diff 的简写是什么?我以为和git diff HEAD一样,但显然不是。

git diff 将工作树(磁盘上的文件)与索引(分阶段修改)进行比较。

据我所知,它不是任何其他参数组合的 shorthand。


文档的 examples section 很好地解释了“比较最新更改”命令的微妙之处:

Various ways to check your working tree

$ git diff            (1)
$ git diff --cached   (2)
$ git diff HEAD       (3)
  1. Changes in the working tree not yet staged for the next commit.
  2. Changes between the index and your last commit; what you would be committing if you run git commit without -a option.
  3. Changes in the working tree since your last commit; what you would be committing if you run git commit -a

在该列表中:(2)git diff --cached HEAD 的 shorthand,但我不知道还有什么其他方法可以编写 (1)(3).

documentation 总结得很好。

对于git差异

This form is to view the changes you made relative to the index (staging area for the next commit). In other words, the differences are what you could tell Git to further add to the index but you still haven’t.

并且 git diff HEAD 将向您显示索引与 HEAD 之间的区别,后者是您工作树上的最后一次提交。

但直接引用documentation

Changes in the working tree since your last commit; what you would be committing if you run git commit -a