Module 02: Viewing History
Learning Objectives
In this module, you will:
- Understand commit history and how to navigate it
- Use
git logto view commit history with various formats - Use
git showto view specific commit details - Use
git diffto compare changes between commits - Understand commit hashes and references
Challenge
Setup
Run the setup script to create your challenge environment:
.\setup.ps1
This will create a challenge/ directory with a Git repository that already has some commit history.
Your Task
You'll explore an existing Git repository that contains multiple commits. Your goal is to use Git commands to discover information about the repository's history and answer the following questions:
- How many commits are in the repository?
- What was the commit message for the third commit? (counting from the first/oldest commit)
- Which file was modified in the "Fix authentication bug" commit?
- What changes were made to app.py between the first and last commits? (briefly describe)
Create a file called answers.txt in the challenge directory with your answers. You can format your answers however you like, as long as the information is there.
Suggested Approach:
- Navigate to the challenge directory:
cd challenge - View the commit history:
git log - Try different log formats:
git log --oneline,git log --stat - View specific commits:
git show <commit-hash> - Compare commits:
git diff <commit1> <commit2> - Create
answers.txtwith your findings
Important Notes:
- You can use any Git commands you like to explore the repository
- The format of your answers is flexible - just make sure the information is clear
- Try different
git logoptions to see which format you prefer- Commit hashes can be referenced by their full hash or just the first 7 characters
Key Concepts
- Commit Hash: A unique identifier (SHA-1 hash) for each commit. You can use the full hash or just the first few characters.
- Commit Message: A description of what changed in that commit, written by the author.
- Commit History: The chronological record of all changes made to a repository.
- HEAD: A pointer to the current commit you're working from.
Useful Commands
git log # View commit history
git log --oneline # Compact one-line format
git log --stat # Show files changed in each commit
git log --graph # Show branch graph (more useful with branches)
git show <commit> # View specific commit details
git show <commit>:<file> # View a file from a specific commit
git diff <commit1> <commit2> # Compare two commits
git diff <commit> # Compare commit with current working directory
Verification
Once you've created your answers.txt file, verify your solution:
.\verify.ps1
The verification script will check that your answers contain the expected information.
Need to Start Over?
If you want to reset the challenge and start fresh:
.\reset.ps1
This will remove the challenge directory and run the setup script again, giving you a clean slate.