DEV Community

Ayush Poddar
Ayush Poddar

Posted on • Originally published at poddarayush.com

View the changes you have made to your Git repository - Intro to git-diff

This post is part of my “Shorts” series, where each post is concise and hyper-focused on a single concept.

In an earlier post, we discussed how you can stage changes that you make in your Git repository.

What if you want to view the changes you have made before staging your changes? What if you want to view the changes that are there in the staging area before you commit your changes? In this post, I will tell you about git diff which can help you with these questions.

About the command

The command simply is:

git diff <filePath>
Enter fullscreen mode Exit fullscreen mode

where <filePath> is the path to a file whose changes you want to view. The argument <filePath> is optional. If you don't specify the path, git diff will display the changes from all the modified files.

As it is, this command will show you all the changes you have made to your working tree that are ready to be staged.

How to view the staged changes?

If you want to view the staged changes, i.e., the changes that are ready to be committed, you should use the --staged (or --cached) command line flag.

git diff --staged
Enter fullscreen mode Exit fullscreen mode

Further exploration

Run man git-diff in your terminal to learn more about using git diff.

Sources

Top comments (0)