Git 2 reference · Basics

git diff Command (Git)

Show changes: working tree versus staging area, staged changes (--staged), or between commits and branches.

Git 2

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

git diff [--staged] [COMMIT [COMMIT]] [-- PATH]

Parameters

ParameterDescription
(none) Unstaged changes.
--staged Changes staged for the next commit.
A..B / A B Between two commits or branches.
--stat / --name-only Summaries.

Examples

Unstaged changes
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
echo 'Online tea shop' >> README.md
git diff

Output

diff --git a/README.md b/README.md
index a00621b..be4fdf8 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,2 @@
 # Shop
+Online tea shop

Run this on your computer — see “Get Started” for setup.

Staged changes, as a summary
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
echo 'v2' >> README.md; git add README.md
git diff --staged --stat
git diff --name-only HEAD

Output

 README.md | 1 +
 1 file changed, 1 insertion(+)
README.md

Run this on your computer — see “Get Started” for setup.

Was this page helpful?