fix: cleanup revert module

This commit is contained in:
Bjarke Sporring
2026-01-15 16:29:06 +01:00
parent 0474a6de0e
commit cdd695b250

View File

@@ -293,10 +293,10 @@ Use `git revert` when:
Consider alternatives when:
- ❌ **Commits are still local** - Use `git reset` instead (Module 06)
- ❌ **Commits are still local** - Use `git reset` instead (advanced module)
- ❌ **Just want to edit a commit** - Use `git commit --amend`
- ❌ **Haven't pushed yet** - Reset is cleaner for local cleanup
- ❌ **Need to combine commits** - Use interactive rebase
- ❌ **Haven't pushed yet** - Reset is cleaner for local cleanup, but more dangerous, stick to revert if in doubt
- ❌ **Need to combine commits** - Use interactive rebase IF nothing has been pushed to cloud
- ❌ **Reverting creates complex conflicts** - Might need manual fix forward
## Revert vs. Reset vs. Rebase
@@ -344,7 +344,7 @@ git revert --abort
### 1. Using Reset on Pushed Commits
```pwsh
# ❌ NEVER do this with pushed commits
# ❌ NEVER do this with pushed commits. Or at least try your best to avoid it.
git reset --hard HEAD~3
# ✅ Do this instead
@@ -398,99 +398,3 @@ git revert C
- Revert the minimum necessary
- Don't bundle multiple unrelated reverts
- One problem = one revert commit
## Troubleshooting
### "Empty Revert / No Changes"
**Problem:** Revert doesn't seem to do anything.
**Possible causes:**
- Commit was already reverted
- Subsequent commits already undid the changes
- Wrong commit hash
**Solution:**
```pwsh
# Check what the commit actually changed
git show <commit-hash>
# Check if already reverted
git log --grep="Revert"
```
### "Conflicts During Revert"
**Problem:** Revert causes merge conflicts.
**Why:** Subsequent commits modified the same code.
**Solution:**
1. Manually resolve conflicts in affected files
2. `git add <resolved-files>`
3. `git revert --continue`
Or consider fixing forward with a new commit instead of reverting.
### "Reverting Old Commit Breaks Something"
**Problem:** After reverting an old commit, something else stops working.
**Why:** The old commit might have been a dependency for later commits.
**Solution:**
1. Check what changed: `git diff HEAD~1 HEAD`
2. Either fix the issue with a new commit, or
3. Revert the revert if needed: `git revert <revert-commit-hash>`
## Advanced: Revert Internals
Understanding what revert does under the hood:
```pwsh
# Revert creates a new commit with inverse changes
git revert <commit-hash>
# This is equivalent to:
git diff <commit-hash>^..<commit-hash> > changes.patch
patch -R < changes.patch # Apply in reverse
git add .
git commit -m "Revert '<original message>'"
```
**Key insight:** Revert computes the diff of the target commit, inverts it, and applies it as a new commit.
## Going Further
Now that you understand revert, you're ready for:
- **Module 06: Git Reset** - Learn the dangerous but powerful local history rewriting
- **Module 07: Git Stash** - Temporarily set aside uncommitted changes
- **Module 08: Multiplayer Git** - Collaborate with advanced workflows
## Summary
You've learned:
- ✅ `git revert` creates new commits that undo previous changes
- ✅ Revert is safe for shared/pushed commits
- ✅ Commits before and after the reverted commit are preserved
- ✅ Multiple commits can be reverted in one command
- ✅ Revert preserves complete history for audit trails
**The Golden Rule of Revert:** Use revert for any commit that might be shared with others.
## Next Steps
1. Complete both challenge scenarios
2. Run `.\verify.ps1` to check your solutions
3. Experiment with reverting different commits
4. Move on to Module 07: Git Reset (dangerous but powerful!)
---
**Need Help?**
- Review the command reference above
- Check the troubleshooting section
- Re-run `./setup.ps1` to start fresh
- Practice reverting in different orders to understand the behavior