Advertisement
Advertisement


Show git diff on file in staging area


Question

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.

2020/05/06
1
959
5/6/2020 12:28:29 AM

Accepted Answer

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
2015/03/30
1524
3/30/2015 3:19:20 AM

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
2012/09/06

You can also use git diff HEAD file to show the diff for a specific file.

See the EXAMPLE section under git-diff(1)

2018/06/07

Source: https://stackoverflow.com/questions/3527856
Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]