Since git is a version control system, tracking changes are something very vital. Tracking changes between Staging Area, Working Directory, and the Previous Commit is done by git diff command.
If I made some changes into sample.txt file after that if I run git status command then it gives sample.txt as modified file.
Now, after “git add .” command sample.txt is in the staging area. If I again made some changes to sample.txt then it will be in the modified area as well as in the staging area also.
Above you can see that sample.txt is highlighted in green, it means it is in staging area, under that sample.txt is in red it means sample.txt is modified area also.
To compare the Staging area and Working Directory following command is used:
This output says that you have replaced “hello” with “hello Hey there this is a change” in the sample.txt file. So here it is comparing it with the Staging area and current working state.
Now if you want to compare the staging area and previous commit, then there is also one command which is:
git diff --staged
In output previous commit is highlighted by green color and staging area is shown by red colored text.