git diff: --cached 和 --staged 有什么区别

git diff: what is the difference between --cached and --staged

将分阶段与上次提交进行比较:

git diff --cached
git diff --staged

这两个命令生成相同的结果,对吗?

git diff 的文档说“--staged 是 --cached 的同义词”,所以是的。

来自文档 - --staged 是 --cached

的同义词

git-scm.com/docs/git-diff(见粗体文本):

git diff [<options>] --cached [<commit>] [--] [<path>…​]

This form is to view the changes you staged for the next commit relative to the named <commit>. Typically you would want comparison with the latest commit, so if you do not give , it defaults to HEAD. If HEAD does not exist (e.g. unborn branches) and is not given, it shows all staged changes. --staged is a synonym of --cached.