Git
Version Control
Uncommitted Changes
Git Diff
Git Tutorial

How to show uncommitted changes in Git and some Git diffs in detail

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

Inspecting uncommitted changes is the fastest way to prevent accidental regressions before a commit. Git provides lightweight summaries and deep diff tools for both staged and unstaged edits. A repeatable review sequence helps you catch missing files, noisy formatting changes, and incorrect logic early.

Start with a Clean Overview

Run status first so you know what category each file belongs to.

bash
git status -sb

The short format gives a compact view of modified, added, deleted, and untracked paths. After that, check the size and distribution of changes.

bash
git diff --stat
git diff --numstat

--stat is human-friendly, while --numstat is useful for scripts and CI hooks.

Inspect Unstaged and Staged Diffs Separately

Unstaged and staged diffs are different working sets. Review both every time.

bash
1# Unstaged edits against index
2git diff
3
4# Staged edits against HEAD
5git diff --cached

For better readability in long lines, word-level mode helps highlight exact token changes.

bash
git diff --word-diff
git diff --cached --word-diff

If whitespace noise is distracting, ignore it temporarily, then recheck without ignore before committing.

bash
git diff -w
git diff --cached -w

Ignoring whitespace can hide real indentation-sensitive changes in languages such as Python, so use it only as a secondary view.

Focus on Specific Files or Hunks

When a commit touches many files, path-scoped diffs keep review manageable.

bash
git diff -- src/service/payment.ts
git diff --cached -- src/service/payment.ts

You can also compare your work tree file directly against a known commit.

bash
git diff HEAD~1 -- src/service/payment.ts

For larger refactors, a function-context view often shows intent better.

bash
git diff --function-context

This includes surrounding function blocks, which is useful when logic spans many small line changes.

Review Rename and Mode Changes

Some risky edits are not obvious in default diff output. Include metadata checks.

bash
git diff --summary
git diff --cached --summary

This reveals renames, permission mode changes, and file type transitions. In deployment scripts and executables, mode changes are especially important.

Build a Personal Pre-Commit Checklist

A practical sequence that works well in most repos is:

bash
1git status -sb
2git diff --stat
3git diff
4git diff --cached
5git diff --cached --check

--check highlights whitespace errors and conflict markers in staged content. Add this sequence to an alias or shell function to make it habitual.

bash
git config --global alias.review '!git status -sb && git diff --stat && git diff && git diff --cached && git diff --cached --check'

Then run git review before every commit.

Compare Against Merge Base for Review Prep

Before opening a pull request, inspect differences from the merge base rather than only from local HEAD. This view reflects what reviewers will see once your branch is compared with the target branch.

bash
base=$(git merge-base HEAD origin/main)
git diff --stat "$base"...HEAD
git diff "$base"...HEAD

Using this check reduces surprises caused by rebases or stale local assumptions about branch history.

Common Pitfalls

  • Reviewing only unstaged changes and forgetting staged changes.
  • Relying on -w output and missing indentation-sensitive bugs.
  • Skipping rename and mode checks for deploy scripts or executable files.
  • Committing debug logs or temporary files because status was not reviewed first.
  • Using huge commits that make diffs too noisy to evaluate accurately.

Summary

  • Start with git status -sb to classify file states quickly.
  • Use git diff and git diff --cached as separate mandatory reviews.
  • Add focused views such as --word-diff, path filters, and function context.
  • Include --summary and --check to catch metadata and whitespace problems.
  • Standardize your review sequence with an alias to reduce human error.

Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions