Your daily Git workflow

Inspect differences

Compare working and staged changes before recording them.

git diff compares project states. The command you choose decides which states Git compares.

See working-tree changes that are not staged:

git diff

This compares the working tree with the index.

See the snapshot prepared for the next commit:

git diff --staged

This compares the index with HEAD.

To inspect everything changed since the current commit, including staged and unstaged work, use:

git diff HEAD

What diff does not show

Untracked files do not appear in a normal diff because Git has no recorded version to compare. Find them with git status.

Review both ordinary and staged diffs before committing. This catches debug output, accidental edits, and changes staged from an older version of a file.

I run git diff --staged on almost every commit. It takes ten seconds and saves me from pushing a console.log I forgot about.

You can also compare two commits directly:

git diff HEAD~1 HEAD

That shows what changed between the previous commit and the current one. Useful when you want to review work you already committed.

Color output helps scan hunks quickly. Git enables it by default in most terminals. Lines starting with - were removed. Lines starting with + were added.

To see only the names of changed files without line details:

git diff --name-only

Add --staged when you want the list for the next commit instead of unstaged edits.

Word-diff mode can help with prose files:

git diff --word-diff README.md

It highlights changed words inside a line instead of replacing the whole line.

Try this on your own project: stage one edit, make another edit in the same file, then run all three commands. Explain why each diff is different.

Lesson completed