git diff
The command that shows the differences between two of Git's states: the working tree, the staging area, or any two commits.
In more detail
git diff alone compares the working tree with the staging area, so it shows changes not yet staged. git diff --staged compares the staging area with the last commit, and git diff HEAD compares the working tree with the last commit. git diff A B compares two commits, and git diff A...B compares B with the merge base, which is what a review shows.
Example
git diff --stat HEAD~1 HEADRelated terms
- diff — A listing of the differences between two versions of something, such as two files, two commits or two screenshots.
- --staged — A flag that points a command at the staging area instead of the working tree, as in git diff --staged or git restore --staged.
- commit range — Two revisions joined by dots to name a set of commits, or with git diff to choose which two states to compare.
- --stat — Flags for git diff, git log and git show that summarise a change per file instead of printing every line: --stat counts lines and --name-status gives a letter per file.
- three areas — Git's model of where a change can be: the working tree on disk, the staging area waiting for the next commit, and the repository of recorded commits.
Taught in
- The Three Areas: Working Tree, Index, Repository — Advanced Git Internals & Distributed Workflows
- Staging Deliberately: status, add, add --patch — Advanced Git Internals & Distributed Workflows
- Committing, And What A Good Message Says — Advanced Git Internals & Distributed Workflows
- Reading History: log, show And diff — Advanced Git Internals & Distributed Workflows