Synopsis
Description
Show changes between the working tree and the index or a tree, changes between the index and a tree, changes between two trees, changes resulting from a merge, changes between two blob objects, or changes between two files on disk. Thegit diff command is one of the most frequently used Git commands for reviewing changes before staging or committing them.
Common Usage
Options
--cached (--staged)
--cached (--staged)
View the changes you staged for the next commit relative to the named commit (typically This shows what you would be committing if you run
HEAD).git commit without -a option.--no-index
--no-index
Compare two paths on the filesystem without requiring a Git repository.
--merge-base
--merge-base
Instead of comparing directly, use the merge base of the commits.Equivalent to
git diff $(git merge-base main feature) feature.--stat
--stat
Generate a diffstat showing which files changed and by how much.
--name-only
--name-only
Show only names of changed files.
--name-status
--name-status
Show only names and status of changed files (Added, Modified, Deleted).
--diff-filter
--diff-filter
Select only files that are Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R), or have their type changed (T).
-R
-R
Swap the input sources, showing the diff in reverse.
Examples
Checking your working tree
Comparing with arbitrary commits
Comparing branches
Limiting the diff output
Advanced options
Related Commands
- git status - Show the working tree status
- git log - Show commit logs with diffs
- git add - Add file contents to the index
- git commit - Record changes to the repository
- git show - Show various types of objects
