Back
GitoryxGitoryx

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.

Beginner8 min readUpdated

On this page

What is git diff?

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.

The short version

  1. 1See unstaged changes: git diff
  2. 2See staged changes: git diff --staged
  3. 3Diff a specific file: git diff <file>
  4. 4Compare branches: git diff main feature/branch
  5. 5Compare commits: git diff <sha1> <sha2>

Why it matters

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.

Where it usually goes wrong

  • 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

Git diff, step by step

  1. Step 1: See unstaged changes (working directory vs index)

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

    Terminal
    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;

    Tip: Lines starting with - are removed; lines starting with + are added.

  2. Step 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.

    Terminal
    git diff --staged

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

  3. Step 3: Diff a specific file

    Limit the diff to one file to reduce noise.

    Terminal
    git diff src/app.tsgit diff --staged src/app.ts
  4. Step 4: Diff between two commits

    Compare any two commits using their SHAs or relative references.

    Terminal
    # Between two SHAsgit diff a3f2c1d 9b1e4fa# Current commit vs three commits agogit diff HEAD~3 HEAD
    Git Diff: See What Changed Before You Commit: the same workflow in Gitoryx
    In Gitoryx: Side-by-side diff view for every changed fileHow it works
  5. Step 5: Diff between two branches

    See all changes between a feature branch and main.

    Terminal
    git diff main feature/login# See only the file names that differ:git diff main feature/login --name-only
  6. Step 6: See a word-level diff

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

    Terminal
    git diff --word-diff

Mistakes to avoid with git diff

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.

Git diff in Gitoryx

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

  • 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

Free plan · no account required · macOS, Windows and Linux

Git diff: 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.
All Git tutorials →
Gitoryx

Stop fighting Git. Start shipping.

Download the fast, native Git client that developers actually enjoy using.

v1.1.0 · macOS 12+ (Apple Silicon or Intel) · Windows 10+ · Linux x86_64