feat: add more challenges to the history module

This commit is contained in:
Bjarke Sporring
2026-01-07 20:12:54 +01:00
parent 5f8091d5b2
commit aefcfbe100
3 changed files with 259 additions and 57 deletions

View File

@@ -7,7 +7,9 @@ In this module, you will:
- Use `git log` to view commit history with various formats
- Use `git show` to view specific commit details
- Use `git diff` to compare changes between commits
- Use `git diff --staged` to view changes ready to be committed
- Understand commit hashes and references
- Discover how `git diff` reveals changes not visible in current files
## Challenge
@@ -23,7 +25,11 @@ This will create a `challenge/` directory with a Git repository that already has
### 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.
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, including:
- Viewing commit history
- Examining changes between specific commits
- Understanding staged changes
- **Finding a secret code hidden in the commit history!** (Only discoverable by using `git diff`)
The setup script will create an `answers.md` file in the challenge directory with questions for you to answer. Fill in your answers directly in that file.
@@ -31,17 +37,19 @@ The setup script will create an `answers.md` file in the challenge directory wit
1. Navigate to the challenge directory: `cd challenge`
2. Open `answers.md` to see the questions
3. View the commit history: `git log`
4. Try different log formats: `git log --oneline`, `git log --stat`
5. View specific commits: `git show <commit-hash>`
6. Compare commits: `git diff <commit1> <commit2>`
7. Fill in your answers in `answers.md`
3. View the commit history: `git log` or `git log --oneline`
4. Check repository status: `git status`
5. View staged changes: `git diff --staged`
6. Try different log formats: `git log --stat`, `git log --graph`
7. View specific commits: `git show <commit-hash>`
8. Compare specific commits: `git diff <commit1> <commit2> <file>`
9. Fill in your answers in `answers.md`
> **Important Notes:**
> - You can use any Git commands you like to explore the repository
> - Fill in your answers directly in the `answers.md` file (there are placeholder sections for each answer)
> - Try different `git log` options to see which format you prefer
> - Commit hashes can be referenced by their full hash or just the first 7 characters
> - Notice that one file is already staged - use `git diff --staged` to see what it contains
## Key Concepts
@@ -50,6 +58,11 @@ The setup script will create an `answers.md` file in the challenge directory wit
- **Commit History**: The chronological record of all changes made to a repository.
- **HEAD**: A pointer to the current commit you're working from.
- **Diff**: A view showing the differences between two versions of files.
- **Staging Area**: Where changes wait before being committed. Use `git diff --staged` to see what's ready to commit.
- **Working Directory vs Staged vs Committed**:
- Working Directory: Files you're currently editing
- Staged (Index): Changes marked for the next commit (via `git add`)
- Committed: Changes permanently saved in history
## Understanding Diff Output
@@ -144,16 +157,23 @@ diff --git a/auth.py b/auth.py
In this module's challenge, you'll use:
```bash
git diff <commit1> <commit2> app.py
# See what's staged for the next commit
git diff --staged
# Compare changes between specific commits
git diff <commit2> <commit4> app.py
```
Pay attention to:
- Which lines were added (green, with `+`)
- Which lines were removed (red, with `-`)
- The surrounding context (white, with space)
- How `git diff --staged` shows only changes ready to commit
## Useful Commands
### Viewing History
```bash
git log # View commit history
git log --oneline # Compact one-line format
@@ -161,10 +181,29 @@ 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
```
### Comparing Changes with git diff
```bash
# Compare commits
git diff <commit1> <commit2> # Compare two commits
git diff <commit1> <commit2> <file> # Compare specific file between commits
git diff <commit> # Compare commit with current working directory
# Compare staged changes
git diff --staged # Show changes in staging area (ready to commit)
git diff --cached # Same as --staged (alternative syntax)
git diff # Show unstaged changes in working directory
git diff HEAD # Show all changes (staged + unstaged) vs last commit
```
**When to use each `git diff` variant:**
- `git diff` - See what you've changed but haven't staged yet
- `git diff --staged` - Review what you're about to commit
- `git diff HEAD` - See all your changes since the last commit
- `git diff <commit1> <commit2>` - Compare any two points in history
## Verification
Once you've filled in your answers in `answers.md`, verify your solution: