Git diff commands show you exactly what changed in your working directory. Whether you want to see unstaged modifications, check what you have staged for commit, or compare different branches, Git diff gives you the power to view changes in various states and contexts.
Showing Working Directory Changes
Use git diff HEAD to see all changes between your current working directory and the last commit. This shows you what you've modified but haven't staged yet.
$ git diff HEAD
Try it Yourself โ
Showing Staged Changes
The git diff --cached command (also known as git diff --staged) shows you what changes you've prepared for the next commit. This helps you review your planned changes before committing.
$ git diff --cached
Try it Yourself โ
Comparing Different Branches
To see what changes exist between your current branch and another branch, use git diff branch-name. This is useful for understanding what you're working on versus what's already done in another branch.
$ git diff feature-login
Try it Yourself โ