advanced · 29 minute study
Undo a shared change without pretending it never happened
Choose a recovery operation based on what must be preserved: working edits, staged content, published history and other people's later changes.
Useful preparation · 1 prerequisite
Use this as a map, not a lock. If these ideas are familiar, continue.
- Replaying a change creates new history objects — Understand when replaying commits is useful and why the same operation becomes disruptive after others depend on the published history.
First, build a mental model
Revert adds a new commit that counteracts a selected change. Reset moves the current history reference and, depending on mode, also changes the index or working tree. They solve different recovery problems.
- On shared history, a revert is often the appropriate starting point because it records the undo as new history rather than removing published commits.
- reset --soft leaves index and working tree content; mixed reset also resets the index while keeping working files.
- reset --hard resets index and tracked working content and can discard work. It can also remove untracked paths that obstruct writing tracked paths; do not treat it as harmless cleanup.
- A revert can conflict with later changes. Verify the intended resulting behavior rather than assuming inversion is always automatic.
- Reflogs can help locate prior local reference positions, but they are not a guarantee that every uncommitted or untracked file can be recovered.
# In a controlled recovery branch, inspect before changing history:
git status
git log --oneline -5
git show BUG_COMMIT
# After identifying the intended inverse change:
git revert BUG_COMMIT
# Resolve any conflict carefully and run the relevant regression checks.
# BUG_COMMIT is an educational placeholder for a reviewed real commit.- Published history
A buggy commit and later useful commits are already shared.
- Revert
A new commit records the inverse change where it can be applied.
- Verify
The history remains reviewable, but later code dependencies may require a deliberate resolution and tests.
Production thinking
Take this beyond the example.
Preserve recoverable work before mutations, favor reviewable corrections to shared branches and verify behavior after recovery. Reverting code also does not automatically undo already-applied database migrations or real-world side effects.
Sources and further reading
Your evidence
unseen is a local learning signal, not a credential or proof of production competence.
Explain the mental model, then explicitly acknowledge it. Opening a page is not evidence.
Supported retries can complete this lesson. Independent evidence and delayed review determine the skill stage.
Next lesson · A release claim needs a source snapshot and an artifact →