fix: revert conflict
This commit is contained in:
@@ -35,8 +35,8 @@ Before starting this module, you should be comfortable with:
|
||||
|
||||
Run the setup script to create the challenge environment:
|
||||
|
||||
```powershell
|
||||
./setup.ps1
|
||||
```pwsh
|
||||
.\setup.ps1
|
||||
```
|
||||
|
||||
This creates a `challenge/` directory with three branches demonstrating different revert scenarios:
|
||||
@@ -52,44 +52,57 @@ You're working on a calculator application. A developer added a `divide` functio
|
||||
|
||||
### Your Task
|
||||
|
||||
1. Navigate to the challenge directory:
|
||||
```bash
|
||||
1. **Navigate to the challenge directory:**
|
||||
```pwsh
|
||||
cd challenge
|
||||
```
|
||||
|
||||
2. You should be on the `regular-revert` branch. View the commit history:
|
||||
```bash
|
||||
2. **Check which branch you're on** (you should be on `regular-revert`):
|
||||
```pwsh
|
||||
git branch
|
||||
```
|
||||
The `*` should be next to `regular-revert`.
|
||||
|
||||
3. **View the commit history:**
|
||||
```pwsh
|
||||
git log --oneline
|
||||
```
|
||||
|
||||
3. Find the commit with the broken divide function (message: "Add broken divide function - needs to be reverted!")
|
||||
4. **Find the commit with message:** "Add broken divide function - needs to be reverted!"
|
||||
- Note the commit hash (the 7-character code at the start, like `a1b2c3d`)
|
||||
- Write it down or copy it
|
||||
|
||||
4. Revert that specific commit:
|
||||
```bash
|
||||
5. **Revert that specific commit** (replace `<commit-hash>` with the actual hash):
|
||||
```pwsh
|
||||
git revert <commit-hash>
|
||||
```
|
||||
|
||||
5. Git will open your editor for the revert commit message. The default message is fine—save and close.
|
||||
6. **Visual Studio Code will open** with the revert commit message:
|
||||
- The default message is fine (it says "Revert 'Add broken divide function...'")
|
||||
- Close the editor window to accept the commit message
|
||||
- Git will create the revert commit
|
||||
|
||||
### What to Observe
|
||||
|
||||
After reverting, check:
|
||||
After reverting, check your work:
|
||||
|
||||
```bash
|
||||
# View the new revert commit
|
||||
```pwsh
|
||||
# View the new revert commit in history
|
||||
git log --oneline
|
||||
|
||||
# Check that divide function is gone
|
||||
cat calculator.py | grep "def divide" # Should return nothing
|
||||
# Check that divide.py file is gone (reverted)
|
||||
ls
|
||||
# You should see calculator.py but NOT divide.py
|
||||
|
||||
# Check that modulo function still exists (it came after the bad commit)
|
||||
cat calculator.py | grep "def modulo" # Should find it
|
||||
# Check that modulo function still exists in calculator.py (it came after the bad commit)
|
||||
cat calculator.py
|
||||
# You should see def modulo
|
||||
|
||||
# Check that multiply function still exists (it came before the bad commit)
|
||||
cat calculator.py | grep "def multiply" # Should find it
|
||||
# (You already see it when you cat the file above)
|
||||
```
|
||||
|
||||
**Key insight:** Revert creates a new commit that undoes the changes from the target commit, but leaves all other commits intact.
|
||||
**Key insight:** Revert creates a NEW commit that undoes the changes from the target commit, but leaves all other commits intact.
|
||||
|
||||
### Understanding the Timeline
|
||||
|
||||
@@ -141,35 +154,43 @@ When reverting a merge, you must specify which parent to keep using the `-m` fla
|
||||
|
||||
### Your Task
|
||||
|
||||
1. Switch to the merge-revert branch:
|
||||
```bash
|
||||
1. **Switch to the merge-revert branch:**
|
||||
```pwsh
|
||||
git switch merge-revert
|
||||
```
|
||||
|
||||
2. View the commit history and find the merge commit:
|
||||
```bash
|
||||
2. **View the commit history with the graph:**
|
||||
```pwsh
|
||||
git log --oneline --graph
|
||||
```
|
||||
|
||||
Look for: "Merge feature-auth branch"
|
||||
Look for the merge commit message: "Merge feature-auth branch"
|
||||
- Note the commit hash
|
||||
- Write it down or copy it
|
||||
|
||||
3. Revert the merge commit using `-m 1`:
|
||||
```bash
|
||||
3. **Revert the merge commit using `-m 1`** (replace `<merge-commit-hash>` with actual hash):
|
||||
```pwsh
|
||||
git revert -m 1 <merge-commit-hash>
|
||||
```
|
||||
|
||||
**Explanation:**
|
||||
- `-m 1` tells Git to keep parent 1 (main branch)
|
||||
**What `-m 1` means:**
|
||||
- `-m 1` tells Git to keep parent 1 (the main branch side)
|
||||
- This undoes all changes from the feature-auth branch
|
||||
- Creates a new "revert merge" commit
|
||||
|
||||
4. Save the default commit message and check the result:
|
||||
```bash
|
||||
# Verify auth.py is gone
|
||||
ls auth.py # Should not exist
|
||||
4. **Visual Studio Code will open** with the revert commit message:
|
||||
- Close the editor window to accept it
|
||||
- Git will create the revert commit
|
||||
|
||||
5. **Check the result:**
|
||||
```pwsh
|
||||
# View files - auth.py should be gone
|
||||
ls
|
||||
# You should see calculator.py but NOT auth.py
|
||||
|
||||
# Verify calculator.py no longer imports auth
|
||||
cat calculator.py | grep "from auth" # Should return nothing
|
||||
cat calculator.py
|
||||
# Should NOT see "from auth import" anywhere
|
||||
```
|
||||
|
||||
### What Happens Without -m?
|
||||
@@ -242,44 +263,48 @@ Two separate commits added broken mathematical functions (`square_root` and `log
|
||||
|
||||
### Your Task
|
||||
|
||||
1. Switch to the multi-revert branch:
|
||||
```bash
|
||||
1. **Switch to the multi-revert branch:**
|
||||
```pwsh
|
||||
git switch multi-revert
|
||||
```
|
||||
|
||||
2. View the commit history:
|
||||
```bash
|
||||
2. **View the commit history:**
|
||||
```pwsh
|
||||
git log --oneline
|
||||
```
|
||||
|
||||
Find the two commits:
|
||||
Find the two bad commits:
|
||||
- "Add broken square_root - REVERT THIS!"
|
||||
- "Add broken logarithm - REVERT THIS TOO!"
|
||||
|
||||
Note both commit hashes (write them down)
|
||||
|
||||
3. Revert both commits in one command:
|
||||
```bash
|
||||
3. **Revert both commits in one command** (replace with actual hashes):
|
||||
```pwsh
|
||||
git revert <commit-hash-1> <commit-hash-2>
|
||||
```
|
||||
|
||||
**Important:** List commits from **oldest to newest** for cleanest history.
|
||||
**Important:** List commits from **oldest to newest** for cleanest history (square_root first, then logarithm).
|
||||
|
||||
Alternatively, revert them one at a time:
|
||||
```bash
|
||||
**Alternatively**, revert them one at a time:
|
||||
```pwsh
|
||||
git revert <commit-hash-1>
|
||||
git revert <commit-hash-2>
|
||||
```
|
||||
|
||||
4. Git will prompt for a commit message for each revert. Accept the defaults.
|
||||
4. **Visual Studio Code will open TWICE** (once for each revert):
|
||||
- Close the editor each time to accept the default commit message
|
||||
- Git will create two revert commits
|
||||
|
||||
5. Verify the result:
|
||||
```bash
|
||||
# Check that both bad functions are gone
|
||||
cat calculator.py | grep "def square_root" # Should return nothing
|
||||
cat calculator.py | grep "def logarithm" # Should return nothing
|
||||
5. **Verify the result:**
|
||||
```pwsh
|
||||
# View files - sqrt.py and logarithm.py should be gone
|
||||
ls
|
||||
# You should see calculator.py but NOT sqrt.py or logarithm.py
|
||||
|
||||
# Check that good functions remain
|
||||
cat calculator.py | grep "def power" # Should find it
|
||||
cat calculator.py | grep "def absolute" # Should find it
|
||||
# Check that good functions remain in calculator.py
|
||||
cat calculator.py
|
||||
# You should see def power and def absolute
|
||||
```
|
||||
|
||||
### Multi-Revert Strategies
|
||||
@@ -311,11 +336,17 @@ This is useful when reverting multiple commits and you want one combined revert
|
||||
|
||||
## Verification
|
||||
|
||||
Verify your solutions by running the verification script:
|
||||
After completing all three challenges, verify your solutions:
|
||||
|
||||
```bash
|
||||
cd .. # Return to module directory
|
||||
./verify.ps1
|
||||
```pwsh
|
||||
cd .. # Return to module directory (if you're in challenge/)
|
||||
.\verify.ps1
|
||||
```
|
||||
|
||||
Or from inside the challenge directory:
|
||||
|
||||
```pwsh
|
||||
..\verify.ps1
|
||||
```
|
||||
|
||||
The script checks that:
|
||||
@@ -329,7 +360,7 @@ The script checks that:
|
||||
|
||||
### Basic Revert
|
||||
|
||||
```bash
|
||||
```pwsh
|
||||
# Revert a specific commit
|
||||
git revert <commit-hash>
|
||||
|
||||
@@ -342,7 +373,7 @@ git revert HEAD~1
|
||||
|
||||
### Merge Commit Revert
|
||||
|
||||
```bash
|
||||
```pwsh
|
||||
# Revert a merge commit (keep parent 1)
|
||||
git revert -m 1 <merge-commit-hash>
|
||||
|
||||
@@ -352,7 +383,7 @@ git revert -m 2 <merge-commit-hash>
|
||||
|
||||
### Multiple Commits
|
||||
|
||||
```bash
|
||||
```pwsh
|
||||
# Revert multiple specific commits
|
||||
git revert <hash1> <hash2> <hash3>
|
||||
|
||||
@@ -365,7 +396,7 @@ git revert HEAD~3..HEAD
|
||||
|
||||
### Revert Options
|
||||
|
||||
```bash
|
||||
```pwsh
|
||||
# Revert but don't commit automatically
|
||||
git revert --no-commit <commit-hash>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user