Menu
Coddy logo textTech

Git Diff

Last updated

git diff shows the exact line-by-line changes between two states of your repository. With no arguments it shows what you've changed but not yet staged. Add --staged to see what's staged, name two commits or branches to compare them, or name a file to narrow it down.

Try these in the terminal playground - a real shell in your browser, nothing to install.

git diff shows the exact lines that changed between two states - removed lines and added lines.

Syntax

CommandWhat it does
git diffUnstaged changes vs the index
git diff --stagedStaged changes vs the last commit
git diff HEADAll changes since the last commit
git diff main featureDifference between two branches
git diff <hash1> <hash2>Difference between two commits
git diff -- file.txtChanges to a single file

Common cases

GoalCommand
See what you're about to commitgit diff --staged
See uncommitted workgit diff
Compare your branch to maingit diff main
Just the file names that changedgit diff --name-only

Git diff FAQ

What does git diff show by default?
With no arguments, git diff shows changes in your working tree that are not yet staged - what you've edited since the last git add. To see what you've already staged (and will commit next), use git diff --staged; to see everything since the last commit, use git diff HEAD.
What's the difference between git diff and git diff --staged?
git diff compares your working tree to the staging area (unstaged changes). git diff --staged (also --cached) compares the staging area to the last commit (staged changes). Together they show the two halves of your uncommitted work.
How do I diff two branches or commits?
Name them: git diff main feature shows what differs between the two branches, and git diff <hash1> <hash2> compares two commits. Add -- <file> at the end to limit the comparison to one file.
How do I see only which files changed, not the full diff?
Use git diff --name-only for just the filenames, or git diff --stat for a summary showing each file and how many lines changed. These are handy for a quick overview before reading the full line-by-line diff.
Can I practice this online?
Yes. Open the terminal playground to run git diff in a real shell in your browser - nothing to install. Coddy's free interactive Git course also covers inspecting changes step by step.
Coddy programming languages illustration

Learn Git with Coddy

GET STARTED