Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see diff between working directory and staging index?

Tags:

We can see difference between repository and working directory with:

git diff 

We can see difference between repository and staging index with:

git diff --staged 

But how do we see difference between working directory and staging index?

like image 374
matori82 Avatar asked Mar 28 '15 16:03

matori82


People also ask

Which command shows the difference between the working directory and the index of staging area?

The git status command will show you the different states of files in your working directory and staging area.

Which command will show the differences between the staged and committed versions of the file?

The git diff command shows the differences between the files in two commits or between your current repository and a previous commit.


2 Answers

Actually, git diff is between index and working tree. It just so happens that until you have staged changes to the index (with git add) that its contents will be identical to the HEAD commit.

git diff HEAD is between repo and working tree.

See 365git.tumblr.com post:

git diffs

like image 93
VonC Avatar answered Oct 06 '22 23:10

VonC


  • git diff - Compare working area to index.
  • git diff --staged - Compare stage area to repository.
  • git diff HEAD - Compare working area to repository

To illustrate that, I changed a file with “Name Staged” text and than I added it (git add .). After that, I changed the file again, now I replaced the text to “Name Working Area” and than I run the follow commands:

enter image description here

Now you can see clearly how it works. Pretty cool, right?

like image 38
Pankwood Avatar answered Oct 06 '22 23:10

Pankwood