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

前端 未结 3 1106
星月不相逢
星月不相逢 2021-02-05 01:29

To compare the staged with the last commit:

git diff --cached
git diff --staged

Both commands generate the same results, right?

相关标签:
3条回答
  • 2021-02-05 02:00

    The documentation for git diff says "--staged is a synonym of --cached", so yes.

    0 讨论(0)
  • 2021-02-05 02:08

    From the docs - --staged is a synonym of --cached

    0 讨论(0)
  • 2021-02-05 02:13

    git-scm.com/docs/git-diff (see bolded text):

    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.

    0 讨论(0)
提交回复
热议问题