How to Show Staged and Unstaged Changes in Git

John Wachira Feb 02, 2024
  1. Show Changes Using git status
  2. Show Changes Using git diff
How to Show Staged and Unstaged Changes in Git

In this article, we will see how we can show the changes we have staged for the next commit and those we have not staged. We can run two commands in Git to display the staged changes.

Let’s start with the basic one.

Show Changes Using git status

We run the git status command to show the state of our working directory. The command shows staged and untracked files in our working directory.

We use the git status command with the --verbose flag to show the staged files. The --verbose option is the same as -v.

$ git status -v

git status verbose

As seen above, the -v option shows the staged file and the file’s content change.

Show Changes Using git diff

We use the git diff command to show changes between our staging area and working directory. You can run the git diff command with the --cached flag to show changes between your staging area and the HEAD.

git diff --cached

git diff

We can run the git diff command with the --name-only --cached flag to display the file names only.

$ git diff --name-only --cached
README.md

The git diff --cached is synonymous with the git diff --staged command.

We can run the git diff command with the HEAD to display both staged and unstaged changes. Let us look at an example.

We will run the git status command to check the state of our working directory.

git status

As seen above, we have a modified README.md file staged for commit and a modified downloadpdf.php file that has not yet been staged for commit. Here is how you can see changes for both files.

git diff HEAD

git diff HEAD

You use the git status command to show staged and unstaged changes. Just add the -vv flag to the command, as shown below.

$ git status -vv

git status vv

The benefit of using the command above is it tells you which file is staged and which one is not staged for commit.

Author: John Wachira
John Wachira avatar John Wachira avatar

John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.

LinkedIn

Related Article - Git Diff