How to Show the Changes which Have Been Staged

There might be cases when you staged a few changes to be committed and want to see the difference of all the files staged for the next commit. Here, we suggest a simple solution to check and have success.

Run git diff with --cached option which shows the changes in the cache or index against the current HEAD:

git diff --cached

The --staged option is synonymous with the --cached option. If you cherry-pick what to commit running git add with --patch, the --staged option will get back what is staged.

If you want the file names only run:

git diff --name-only --cached

The git status command has "verbose" option, which also shows the diff between HEAD and the staging area. But you should have staged changes; otherwise, this command won't work.

git status -v

The git diff Command

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

The git diff HEAD command shows all the changes made between the working directory and HEAD, 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 git status 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 -- verbose option not only shows the names of changed files but also displays the textual changes staged to be committed. The -v option defined twice will show not staged changes in the working tree.

Do you find this helpful?

Related articles