git diff
See exactly what changed in your files, line by line
What it does
git diff shows the difference line by line: removed lines are marked -, added ones +. With no arguments it compares the files in your folder with the index, which means the edits you have not staged with git add yet.
With --staged (also --cached) it compares the index with the last commit: exactly what the next commit will contain. Handy to check before git commit. Name a file to see just that file, or two commits to compare them.
Syntax
git diff
git diff <file>
git diff --staged
git diff <commit> <commit>Examples
Show the changes that are not staged yet
git diffdiff— difference: working tree vs index
Show the changes that are already staged
git diff --stagedsame as:
git diff --cacheddiff— difference--staged— index vs the last commit
Related commands
- git status — See what changed in the folder and what is already staged
- git add — Stage changes so they go into the next commit
- git show — Show one commit: its message, author and every change in it