DevOpsSchool Logo

git diff's Examples

This command shows the file differences which are not yet staged.

git diff

This command shows the differences between the files in the staging area and the latest version present.

git diff –staged

This command shows the differences between the two branches mentioned.

git diff [first branch] [second branch]

Shows unstaged file differences

$ git diff

Shows file differences between staging and the last file version

$ git diff --staged

Shows unstaged changes (working directory vs. staging)

git diff

Shows staged changes (staging area vs. last commit)

git diff --staged

Shows all changes (working directory + staging vs. last commit)

git diff HEAD

Compares two commits

git diff abc123 def456

Compares two branches

git diff main dev

Compares current state with previous commit

git diff HEAD~1

Shows unstaged changes in a file

git diff README.md

Shows unstaged changes in a file

git diff README.md

Shows staged changes in a file

git diff --staged index.js

Shows changes to a file between two commits

git diff abc123 def456 -- app.py

Lists only changed file names

git diff --name-only

Shows names and status of changed files (A, M, D)

git diff --name-status

Shows summary of changes (insertions/deletions)

git diff --stat

Forces colorized output

git diff --color

Shows word-level changes

git diff --word-diff

Compare working directory with a specific commit

git diff abc123

Show difference for one file

git diff HEAD -- index.html

Compare local repo with remote tracking branch

git diff origin/main

Outputs diff in patch format (default)

git diff --patch

Includes binary files in patch output

git diff --binary

Save diff as patch file

git diff > fix.patch

Ignores whitespace changes

git diff -w

Ignores changes in whitespace at end of lines

git diff --ignore-space-at-eol

Ignores all whitespace when comparing lines

git diff --ignore-all-space

Compare last two commits

git diff HEAD^ HEAD

Shows trailing whitespace errors

git diff --check

Compare two directories outside a repo

git diff --no-index src/ backup/

DevOpsSchool
Typically replies within an hour

DevOpsSchool
Hi there 👋

How can I help you?
×
Chat with Us