learn.colinkim.dev

Git: understanding status, diff, and history

Learn how to inspect what changed, what is staged, and what has already been recorded in the repository.

After making a repository and a first commit, the next job is learning how to inspect what is happening.

Three commands matter immediately:

  • git status
  • git diff
  • git log

git status tells you the current state of the repository

Run:

git status

This shows:

  • which branch you are on
  • which files changed
  • which files are staged
  • which files are untracked

For beginners, git status is the safest command to run when you are unsure what is happening.

Quick Check

One answer

What does git status NOT show?

Choose the best answer and use it to track your progress through the lesson.

It is also one of the best places to reinforce the three-state model:

  • some changes are only in the working tree
  • some changes are staged for the next commit
  • some changes are already part of commit history

git diff shows the actual content changes

To see unstaged changes:

git diff

To see what is already staged for the next commit:

git diff --staged

This distinction matters:

  • git diff shows what changed in the working tree but is not staged yet
  • git diff --staged shows what Git would include if you committed now

That means git diff --staged is one of the best commands to run right before git commit.

git log shows commit history

To inspect the history:

git log

A shorter common view is:

git log --oneline

That gives a compact list of recent commits with short identifiers and commit messages.

Quick Check

One answer

What does git log --oneline display?

Choose the best answer and use it to track your progress through the lesson.

A practical inspection habit

Before making a commit, a strong habit is:

  1. run git status
  2. run git diff
  3. stage the intended files
  4. run git diff --staged
  5. commit

That helps you verify the next commit before it becomes part of history.

It also helps prevent a common beginner mistake: assuming Git will automatically commit everything you edited just because the file changed on disk.

.gitignore matters here too

Many repositories include a .gitignore file.

.gitignore tells Git which files or directories should usually be ignored instead of showing up as untracked files.

Common examples include:

  • build output
  • environment files
  • dependency directories
  • editor-specific files

The main idea to keep

Git is easier when you inspect before you act.

git status shows the repository state, git diff shows the content changes, and git log shows the history that already exists.

Progress

Quick checks

No quick checks in this lesson.

Mark lesson manually or answer quick checks to track progress.