W3docs

How to Show the Changes which Have Been Staged in Git

Read this tutorial and know which commands are used to make it possible to show the changes which have been changed. Other methods are also discussed.

There might be cases when, after staging several changes to be committed, you wish to see the differences of all the files staged for the next commit. Here, we suggest some simple solutions to use and succeed.

How to show changes using git diff

Run git diff with the <kbd class="highlighted">--cached</kbd> option, which shows the staged changes for the next commit compared to the <kbd class="highlighted">HEAD</kbd>:

shows the changes in the cache, git diff

git diff --cached

The <kbd class="highlighted">--staged</kbd> option is synonymous with the <kbd class="highlighted">--cached</kbd> option.

If you want to see only the file names, then run the same command with the <kbd class="highlighted">--name-only</kbd> option:

git diff only file names

git diff --name-only --cached

How to show changes using git status

The git status command has the <kbd class="highlighted">--verbose</kbd> (same as <kbd class="highlighted">-v</kbd>) option, which shows the changes staged for the next commit:

git status verbose

git status -v

The git diff Command

The <kbd class="highlighted">git diff</kbd> command displays the changes between the working directory and the staging area. It is used in combination with <kbd class="highlighted">git status</kbd> and git log commands for analyzing the state of a git repository. The <kbd class="highlighted">--cached</kbd> option displays the changes between the staging area and the <kbd class="highlighted">HEAD</kbd>. It shows what has been added to the staging area and staged for a commit.

The <kbd class="highlighted">git diff</kbd> <kbd class="highlighted">HEAD</kbd> command shows all the changes made between the working directory and <kbd class="highlighted">HEAD</kbd>, including changes in the staging area. It displays all the changes since the last commit, whether staged for commit or not.

The git status Command

The <kbd class="highlighted">git status</kbd> command is run to show the state of the working directory and the staging area. It makes it possible to view the staged changes and the files not being tracked by Git. The status output does not show any information about the committed project history. Use the git log command instead. The <kbd class="highlighted">--verbose</kbd> option not only shows the names of changed files but also displays the textual changes staged to be committed. The <kbd class="highlighted">-v</kbd> option used twice will show unstaged changes in the working tree.