Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show git diff on file in staging area [duplicate]

Is there a way I can see the changes that were made to a file after I have done git add file?

That is, when I do:

git add file git diff file 

no diff is shown. I guess there's a way to see the differences since the last commit but I don't know what that is.

like image 735
arod Avatar asked Aug 20 '10 02:08

arod


People also ask

How do you find the diff in your staging area?

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.

How do I diff two versions of a file in git?

You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch.


2 Answers

You can show changes that have been staged with the --cached flag:

$ git diff --cached 

In more recent versions of git, you can also use the --staged flag (--staged is a synonym for --cached):

$ git diff --staged 
like image 50
mipadi Avatar answered Sep 24 '22 23:09

mipadi


In order to see the changes that have been staged already, you can pass the -–staged option to git diff (in pre-1.6 versions of Git, use –-cached).

git diff --staged git diff --cached 
like image 22
Arturo Herrero Avatar answered Sep 24 '22 23:09

Arturo Herrero