Lesson 4: Understanding Commits

What You'll Learn

In this lesson, you'll dive deeper into commits - the building blocks of your project history. You'll learn what makes a good commit, how to view your history, and best practices.

What is a Commit?

A commit is a snapshot of your project at a specific point in time. Each commit contains:

  • A unique ID (hash) - like a fingerprint
  • Author information - who made the commit
  • Timestamp - when it was made
  • Commit message - what changed
  • The actual changes - what files were modified

Part 1: Viewing Commit History

Basic Log

git log

This shows all commits in reverse chronological order (newest first).

Compact Log

git log --oneline

Shows one line per commit - easier to scan.

Graphical Log

git log --oneline --graph --all

Shows branches and merges visually.

Last N Commits

git log -3

Shows only the last 3 commits.

Part 2: Writing Good Commit Messages

The Formula

A good commit message answers: "If applied, this commit will..."

Good Bad
Add user login form add stuff
Fix button alignment on mobile fixed it
Update README with setup instructions update
Remove unused dependencies cleanup

Conventional Commits

Many teams use prefixes:

  • feat: A new feature
  • fix: A bug fix
  • docs: Documentation changes
  • style: Formatting, whitespace
  • refactor: Code restructuring
  • test: Adding tests

Part 3: What Makes a Good Commit?

One Logical Change Per Commit

Good: Separate commits for:

  • Commit 1: "Add contact form HTML"
  • Commit 2: "Style contact form with CSS"
  • Commit 3: "Add form validation"

Bad: One commit with:

  • "Add contact form, fix header, update footer, and remove old files"

Commit Early, Commit Often

Don't wait until end of day to commit. Make small, frequent commits as you complete each piece.

Part 4: Viewing Changes

See What Changed in a Commit

git show

Shows the most recent commit with full details.

See Specific Commit

git show abc123

Replace abc123 with the commit hash (from git log).

Practice Exercise

  1. Make 3 small changes to your project (add a heading, a paragraph, and a link)
  2. Make a separate commit for each change
  3. View your commit history with git log --oneline
  4. Inspect one commit with git show

Summary

Key Commands

Command What It Does
git log View commit history
git log --oneline Compact commit history
git show View details of a commit

What's Next?

In the next lesson, you'll learn how to work with GitHub - creating repositories online and connecting them to your local repository.