Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

git-diff

To compare the staged with the last commit:

git diff --cached git diff --staged 

Both commands generate the same results, right?

like image 392
Milo Lu Avatar asked Oct 05 '16 15:10

Milo Lu


People also ask

What does git diff -- cached do?

git diff --cached --merge-base A is equivalent to git diff --cached $(git merge-base A HEAD) . This form is to view the changes you have in your working tree relative to the named <commit>. You can use HEAD to compare it with the latest commit, or a branch name to compare with the tip of a different branch.

What is the difference between git diff and git diff -- staged?

git diff --staged will only show changes to files in the "staged" area. git diff HEAD will show all changes to tracked files. If you have all changes staged for commit, then both commands will output the same.

What is another way to call git diff -- staged?

--staged is a synonym of --cached . Stage/cache/index are all synonyms for the staging area.

How do I see staged files in git?

If your changes are already staged, then there's no difference to show. But there's a command line option that will show you staged changes if you specify it: git diff --staged . With the --staged option, git diff will compare your staged changes against the previous commit.


2 Answers

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

like image 168
mkj Avatar answered Sep 18 '22 19:09

mkj


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

like image 33
Shawn Eion Smith Avatar answered Sep 20 '22 19:09

Shawn Eion Smith