feat: add git blame section
This commit is contained in:
@@ -8,6 +8,7 @@ In this module, you will:
|
|||||||
- Use `git show` to view specific commit details
|
- Use `git show` to view specific commit details
|
||||||
- Use `git diff` to compare changes between commits
|
- Use `git diff` to compare changes between commits
|
||||||
- Use `git diff --staged` to view changes ready to be committed
|
- Use `git diff --staged` to view changes ready to be committed
|
||||||
|
- Use `git blame` to find who made specific changes
|
||||||
- Understand commit hashes and references
|
- Understand commit hashes and references
|
||||||
- Discover how `git diff` reveals changes not visible in current files
|
- Discover how `git diff` reveals changes not visible in current files
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@ You'll explore an existing Git repository that contains multiple commits. Your g
|
|||||||
- Examining changes between specific commits
|
- Examining changes between specific commits
|
||||||
- Understanding staged changes
|
- Understanding staged changes
|
||||||
- **Finding a secret code hidden in the commit history!** (Only discoverable by using `git diff`)
|
- **Finding a secret code hidden in the commit history!** (Only discoverable by using `git diff`)
|
||||||
|
- **Tracking down who made a suspicious code change** (Using `git blame`)
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
@@ -43,7 +45,8 @@ The setup script will create an `answers.md` file in the challenge directory wit
|
|||||||
6. Try different log formats: `git log --stat`, `git log --graph`
|
6. Try different log formats: `git log --stat`, `git log --graph`
|
||||||
7. View specific commits: `git show <commit-hash>`
|
7. View specific commits: `git show <commit-hash>`
|
||||||
8. Compare specific commits: `git diff <commit1> <commit2> <file>`
|
8. Compare specific commits: `git diff <commit1> <commit2> <file>`
|
||||||
9. Fill in your answers in `answers.md`
|
9. Use `git blame` to find who wrote specific lines: `git blame -e <file>`
|
||||||
|
10. Fill in your answers in `answers.md`
|
||||||
|
|
||||||
> **Important Notes:**
|
> **Important Notes:**
|
||||||
> - You can use any Git commands you like to explore the repository
|
> - You can use any Git commands you like to explore the repository
|
||||||
@@ -204,6 +207,19 @@ git diff HEAD # Show all changes (staged + unstaged) vs last c
|
|||||||
- `git diff HEAD` - See all your changes since the last commit
|
- `git diff HEAD` - See all your changes since the last commit
|
||||||
- `git diff <commit1> <commit2>` - Compare any two points in history
|
- `git diff <commit1> <commit2>` - Compare any two points in history
|
||||||
|
|
||||||
|
### Finding Who Changed What with git blame
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git blame <file> # Show who last modified each line
|
||||||
|
git blame -e <file> # Show with email addresses
|
||||||
|
git blame -L 10,20 <file> # Blame specific line range (lines 10-20)
|
||||||
|
```
|
||||||
|
|
||||||
|
**When to use `git blame`:**
|
||||||
|
- Find who wrote a specific line of code
|
||||||
|
- Identify when a bug was introduced
|
||||||
|
- Understand the context/reason for a change by finding the author
|
||||||
|
|
||||||
## Verification
|
## Verification
|
||||||
|
|
||||||
Once you've filled in your answers in `answers.md`, verify your solution:
|
Once you've filled in your answers in `answers.md`, verify your solution:
|
||||||
|
|||||||
@@ -200,6 +200,39 @@ Set-Content -Path "app.py" -Value $appContent
|
|||||||
git add .
|
git add .
|
||||||
git commit -m "Add user profile feature" | Out-Null
|
git commit -m "Add user profile feature" | Out-Null
|
||||||
|
|
||||||
|
# Commit 6: Add a suspicious change (for git blame challenge)
|
||||||
|
Write-Host "Adding configuration change..." -ForegroundColor Green
|
||||||
|
# Temporarily change git user for this commit
|
||||||
|
git config user.name "Suspicious Developer"
|
||||||
|
git config user.email "guilty@email.com"
|
||||||
|
|
||||||
|
$appContent = @"
|
||||||
|
# app.py - Main application file
|
||||||
|
from auth import login, logout
|
||||||
|
from database import connect, disconnect
|
||||||
|
from profile import get_profile
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print("Welcome to My App!")
|
||||||
|
connect()
|
||||||
|
# Application initialization code here
|
||||||
|
if login("admin", "admin123"): # TODO: Change default credentials!
|
||||||
|
profile = get_profile("admin")
|
||||||
|
print(f"User profile: {profile}")
|
||||||
|
pass
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
"@
|
||||||
|
Set-Content -Path "app.py" -Value $appContent
|
||||||
|
|
||||||
|
git add .
|
||||||
|
git commit -m "Update default login credentials" | Out-Null
|
||||||
|
|
||||||
|
# Reset git config back to original
|
||||||
|
git config user.name "Workshop Student"
|
||||||
|
git config user.email "student@example.com"
|
||||||
|
|
||||||
# Create a staged change scenario
|
# Create a staged change scenario
|
||||||
Write-Host "Creating staged changes for exploration..." -ForegroundColor Green
|
Write-Host "Creating staged changes for exploration..." -ForegroundColor Green
|
||||||
$configContent = @"
|
$configContent = @"
|
||||||
@@ -309,20 +342,26 @@ git diff <commit3-hash> <commit4-hash> database.py
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Question 6: What changes were made to app.py between the second and fourth commits?
|
## Question 6: Who changed the login credentials to hardcoded values? 🔍
|
||||||
|
|
||||||
**Note:** Describe the main changes you observe (new imports, new function calls, etc.)
|
**The Challenge:**
|
||||||
|
Someone on the team added hardcoded login credentials to `app.py` (username: "admin", password: "admin123"). This is a security issue! Use `git blame` to find out who made this change.
|
||||||
|
|
||||||
|
**Your task:** Find the email address of the person who wrote the line containing `login("admin", "admin123")`.
|
||||||
|
|
||||||
**Suggested commands:**
|
**Suggested commands:**
|
||||||
``````bash
|
``````bash
|
||||||
# First, get commit hashes
|
# View who changed each line in app.py
|
||||||
git log --oneline
|
git blame app.py
|
||||||
|
|
||||||
# Then compare commits 2 and 4
|
# For a more readable format
|
||||||
git diff <commit2-hash> <commit4-hash> app.py
|
git blame -e app.py # Shows email addresses
|
||||||
|
|
||||||
|
# Look for the line with login("admin", "admin123")
|
||||||
|
# The format is: commit_hash (Author Name <email> date time line_number) line_content
|
||||||
``````
|
``````
|
||||||
|
|
||||||
**Your Answer:**
|
**Your Answer (provide the email address):**
|
||||||
|
|
||||||
<!-- Write your answer here -->
|
<!-- Write your answer here -->
|
||||||
|
|
||||||
@@ -355,6 +394,14 @@ git diff # Show unstaged changes
|
|||||||
git diff HEAD # Show all changes since last commit
|
git diff HEAD # Show all changes since last commit
|
||||||
``````
|
``````
|
||||||
|
|
||||||
|
**Finding Who Changed What:**
|
||||||
|
``````bash
|
||||||
|
git blame <file> # Show who last modified each line
|
||||||
|
git blame -e <file> # Show with email addresses
|
||||||
|
git blame -L 10,20 <file> # Blame specific line range
|
||||||
|
git blame <file> | grep "pattern" # Find who changed lines matching pattern
|
||||||
|
``````
|
||||||
|
|
||||||
**Repository Status:**
|
**Repository Status:**
|
||||||
``````bash
|
``````bash
|
||||||
git status # Show working tree status
|
git status # Show working tree status
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ if (-not (Test-Path "answers.md")) {
|
|||||||
$answers = Get-Content "answers.md" -Raw
|
$answers = Get-Content "answers.md" -Raw
|
||||||
$answersLower = $answers.ToLower()
|
$answersLower = $answers.ToLower()
|
||||||
|
|
||||||
# Check 1: Contains "5" or "five" for commit count
|
# Check 1: Contains "6" or "six" for commit count
|
||||||
if ($answersLower -match "5|five") {
|
if ($answersLower -match "6|six") {
|
||||||
Write-Host "[PASS] Correct commit count found" -ForegroundColor Green
|
Write-Host "[PASS] Correct commit count found" -ForegroundColor Green
|
||||||
} else {
|
} else {
|
||||||
Write-Host "[FAIL] Commit count not found or incorrect" -ForegroundColor Red
|
Write-Host "[FAIL] Commit count not found or incorrect" -ForegroundColor Red
|
||||||
@@ -93,12 +93,12 @@ if (-not (Test-Path "answers.md")) {
|
|||||||
$allChecksPassed = $false
|
$allChecksPassed = $false
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check 6: Some mention of changes between commits (flexible check)
|
# Check 6: Contains "guilty@email.com" for git blame challenge
|
||||||
if ($answersLower -match "database|connect|disconnect|import|added|validation|error") {
|
if ($answersLower -match "guilty@email\.com") {
|
||||||
Write-Host "[PASS] Changes to app.py between commits described" -ForegroundColor Green
|
Write-Host "[PASS] Correct email address found using git blame!" -ForegroundColor Green
|
||||||
} else {
|
} else {
|
||||||
Write-Host "[FAIL] Changes to app.py between commits not described" -ForegroundColor Red
|
Write-Host "[FAIL] Guilty developer's email not found" -ForegroundColor Red
|
||||||
Write-Host "[HINT] Use 'git diff <commit2> <commit4> app.py' to see changes between specific commits" -ForegroundColor Yellow
|
Write-Host "[HINT] Use 'git blame -e app.py' to see who changed each line with email addresses" -ForegroundColor Yellow
|
||||||
$allChecksPassed = $false
|
$allChecksPassed = $false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,6 +118,7 @@ if ($allChecksPassed) {
|
|||||||
Write-Host " - See which files changed in commits" -ForegroundColor White
|
Write-Host " - See which files changed in commits" -ForegroundColor White
|
||||||
Write-Host " - Check staged changes with git diff --staged" -ForegroundColor White
|
Write-Host " - Check staged changes with git diff --staged" -ForegroundColor White
|
||||||
Write-Host " - Compare changes between specific commits with git diff" -ForegroundColor White
|
Write-Host " - Compare changes between specific commits with git diff" -ForegroundColor White
|
||||||
|
Write-Host " - Track down who made changes with git blame" -ForegroundColor White
|
||||||
Write-Host "`nReady for the next module!" -ForegroundColor Green
|
Write-Host "`nReady for the next module!" -ForegroundColor Green
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user