Commit History Exercise
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
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.
Codemkdir 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
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".
Codeecho "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.
Hint
The message "Add hello.py greeting script" is far more useful than "add file".
- 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.
Codeecho "" >> 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
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.
Codegit log --oneline git logExpected result
Three commits listed, most recent first, each with a clear message.
Try it yourself
# TODO: create repo, make 3 commits with clear messages, then read the log
mkdir history-exercise
cd history-exercise
git initmkdir history-exercise
cd history-exercise
git init
echo "# History Exercise" > README.md
git add .
git commit -m "Initial commit with README"
echo "print('hello')" > hello.py
git add hello.py
git commit -m "Add hello.py greeting script"
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"
git log --oneline
git logWhat 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
- Git Commands MCQ
Quiz on git add, commit, and log behavior.
- Commit Messages MCQ
Identify good vs. bad commit messages.
Related Tools
- Code Diff
Compare changes between commits to see what each commit did.
- .gitignore Generator
Add a .gitignore to keep junk files out of history.
Related Cheatsheets
- Git Cheatsheet
Reference for log flags and commit message conventions.
Related Reference
- Git Commands Reference
Reference for git log flags and commit message conventions.
Related Errors
- Merge Conflict
Resolving conflicting changes.
- Uncommitted Changes
Working with uncommitted changes.
Related Glossary
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Related Errors
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
- Merge Conflict
Resolving conflicting changes.
- Uncommitted Changes
Working with uncommitted changes.