git diff
Viewing unstaged changes
Running git diff with no arguments shows changes in the working tree that have not yet been staged. Use git status first to see which files have been modified.
$ git diff
Viewing staged changes
The --staged flag (also accepted as --cached) shows what is staged and ready to be committed — the diff between the index and the last commit.
$ git diff --staged
Comparing the working tree to the last commit
HEAD refers to the most recent commit on the current branch. This shows both staged and unstaged changes combined.
$ git diff HEAD
Comparing specific commits
Pass two commit references to see what changed between them. The ~1 notation refers to the parent of a commit. You can find commit references with git log.
$ git diff HEAD~1 HEAD
You can also use full or short SHA hashes:
$ git diff a1b2c3d e4f5g6h
For more ways to navigate your commit history, see viewing previous commits.
Comparing branches
The .. syntax shows the diff between the tips of two branches.
$ git diff branch1..branch2
The ... (three-dot) syntax shows changes since the two branches diverged from their common ancestor — useful for reviewing a feature branch without including unrelated changes on the base branch.
$ git diff main...feature/my-branch
Diffing a specific file
Append a file path to any of the above forms to limit the output to that file only.
$ git diff HEAD -- src/app.js
$ git diff branch1..branch2 -- README.md
Once you have reviewed your changes, stage them with git add to prepare the next commit.
Once your code is ready, DeployHQ can deploy it to your servers automatically from any Git repository.