Skip to content

Commit History Exercise

Easy~15 min

What you'll build

A repository with at least three commits, each adding or changing a file. You will read the log and verify that history tells a clear story of what happened.

Goals

  • Make multiple sequential commits with meaningful messages
  • Use git log --oneline for a compact history view
  • See how each commit captures a distinct snapshot
  • Practice writing commit messages that describe the change

Prerequisites

  • git init, add, and commit (the Create Repository Workflow project)

Steps

  1. 1

    Set up the repository

    Create a new repository and make an initial commit with a README. This is the starting point you will build history on top of.

    Code
    mkdir history-exercise
    cd history-exercise
    git init
    echo "# History Exercise" > README.md
    git add .
    git commit -m "Initial commit with README"

    Expected result

    A repository with one commit in its history.

  2. 2

    Add a second file and commit

    Create a new file, stage it, and commit with a message that describes what was added. Good messages say what and why, not just "update".

    Code
    echo "print('hello')" > hello.py
    git add hello.py
    git commit -m "Add hello.py greeting script"

    Expected result

    A second commit is added to the history.

  3. 3

    Modify an existing file and commit

    Append a line to README.md, stage it, and commit. Modifying an existing file is just as common as adding new ones — the workflow is identical.

    Code
    echo "" >> README.md
    echo "## Files" >> README.md
    echo "- hello.py: prints a greeting" >> README.md
    git add README.md
    git commit -m "Document hello.py in README"

    Expected result

    A third commit records the README update.

  4. 4

    Read the history

    Run git log --oneline for a compact one-line-per-commit view. Then run git log to see the full messages, authors, and timestamps. Reading history is how you understand a project's story.

    Code
    git log --oneline
    git log

    Expected result

    Three commits listed, most recent first, each with a clear message.

Try it yourself

What you learned

You built a three-commit history with descriptive messages and read it back with git log — the same skill you use every day to understand what changed in any project and why.

Related Resources

Related Lessons

  • Git Basics

    Commit, add, and log — the commands this exercise drills.

  • Commit Messages

    How to write clear, useful commit messages.

Related Practice

Related Tools

Related Cheatsheets

Related Reference

Related Errors

Related Glossary

  • Commit

    What a commit represents.

  • Branch

    Independent lines of work.

  • Push

    Sending commits to a remote.

Related Glossary

A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.

  • Commit

    What a commit represents.

  • Branch

    Independent lines of work.

  • Push

    Sending commits to a remote.

Related Errors

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

← Back to topic