Back
GitoryxGitoryx
Beginner8 min read

Git Diff: See What Changed Before You Commit

git diff is your window into what has changed in your repository. This tutorial explains how to compare staged vs unstaged changes, diff between branches and commits, and how to read the unified diff format.

The Problem

You've made changes across several files but you can't remember exactly what you modified. You're about to commit but you want to double-check the diff first — and you're not sure which `git diff` command to run.

git diff is your window into change. Reviewing the diff before staging or committing is one of the best habits you can build: it catches accidental changes, debug code left in, and missing files before they enter your history.

Common mistakes developers make with this:

  • Running `git diff` after staging and seeing nothing, because the diff of staged changes requires `--staged`
  • Not reviewing the diff before committing and pushing unwanted changes
  • Misreading the unified diff format (red = removed, green = added)
  • Forgetting you can diff between any two commits or branches

Gitoryx: Gitoryx shows a live side-by-side diff panel as you select files or commits in the UI — no commands needed.

What is Diff: See What Changed Before You Commit?

`git diff` compares two snapshots of your code and shows what changed. By default it compares your working directory to the staging area. Add `--staged` to compare staged changes to the last commit.

Step-by-Step Guide

1

See unstaged changes (working directory vs index)

Running `git diff` with no arguments shows all changes that are not yet staged.

bash
git diff

# Output:
# diff --git a/src/app.ts b/src/app.ts
# --- a/src/app.ts
# +++ b/src/app.ts
# @@ -10,6 +10,7 @@
# -  const old = true;
# +  const updated = true;

Lines starting with `-` are removed; lines starting with `+` are added.

2

See staged changes (index vs last commit)

After `git add`, plain `git diff` shows nothing. Use `--staged` (or `--cached`) to see what's staged.

bash
git diff --staged

Always run this before committing to confirm you're committing exactly what you intended.

3

Diff a specific file

Limit the diff to one file to reduce noise.

bash
git diff src/app.ts
git diff --staged src/app.ts
4

Diff between two commits

Compare any two commits using their SHAs or relative references.

bash
# Between two SHAs
git diff a3f2c1d 9b1e4fa

# Current commit vs three commits ago
git diff HEAD~3 HEAD
See this workflow in Gitoryx — Gitoryx screenshot

See this workflow in Gitoryx. Side-by-side diff view for every changed file

Free download
5

Diff between two branches

See all changes between a feature branch and main.

bash
git diff main feature/login

# See only the file names that differ:
git diff main feature/login --name-only
6

See a word-level diff

For prose or long lines, a word-level diff is easier to read than a line-level diff.

bash
git diff --word-diff

Common Mistakes to Avoid

Forgetting `--staged` after `git add`

After staging, `git diff` shows nothing. Many beginners think their changes disappeared.

Fix: Run `git diff --staged` to see what's staged. Run `git status` to see a summary of staged vs unstaged files.

Not reviewing the diff before `git commit -a`

`git commit -a` stages and commits in one step, bypassing your chance to review.

Fix: Run `git diff` before committing. At minimum, use `git diff --staged` if you've already staged.

Misreading the diff format

The `---` and `+++` headers at the top of each hunk refer to file paths, not removed/added lines. Beginners sometimes confuse them.

Fix: Focus on the `@@ ... @@` hunks where `-` lines are deletions and `+` lines are additions.

Gitoryx — visual Git client for macOS, Windows & Linux
GitoryxGitoryx — macOS, Windows & Linux

Review diffs visually before every commit in Gitoryx

  • Side-by-side diff view for every changed file
  • Click any commit in the graph to see its full diff
  • Stage individual lines directly from the diff panel
  • Word-level highlighting for small inline changes
Download Gitoryx — FreemacOS · Windows · Linux · No subscription

Frequently Asked Questions

Why does `git diff` show nothing after `git add`?

`git diff` compares the working directory to the staging area. Once you've staged your changes with `git add`, the working directory and index are in sync. Use `git diff --staged` to see staged changes.

How do I compare two branches with git diff?

Run `git diff <branch1> <branch2>`. For example `git diff main feature/login` shows what would change if you merged the feature branch into main.

How do I see only the names of changed files?

Use `git diff --name-only`. Add `--name-status` to also see whether each file was Added (A), Modified (M), or Deleted (D).

What does the `@@` line in a diff mean?

The `@@ -a,b +c,d @@` header shows the line range of the hunk. `-a,b` means starting at line `a` for `b` lines in the old file; `+c,d` is the same for the new file.

See it in action with Gitoryx

Everything in this tutorial is faster and clearer with a visual Git client. Gitoryx is free, runs natively on macOS, Windows, and Linux, and built for developers who want to move fast without breaking things.