Revert records an inverse change; reset moves a reference and can alter index or working-tree state. Shared-history undo usually needs a recorded correction.
Before you start
You should understand commits, branches, the working tree and the staging area. Draw the commit graph before changing history. Try commands in a disposable repository with a clean working tree so you can observe exactly which references and files each operation changes.
The practical goal is to reason through this situation: Revert a faulty shared commit so collaborators can follow ordinary history. Read the walkthrough first, then try the interview exercise before opening its answer. The important part is explaining the decision and its consequences, rather than remembering a definition alone.
Step-by-step walkthrough
Step 1: Identify shared history
Decide whether others already depend on the commit being undone.
Step 2: Choose recorded correction
Revert adds an inverse commit suitable for ordinary shared-history recovery.
Step 3: Validate the outcome
Dependencies added later can make an inverse patch insufficient by itself.
Worked scenario
Revert a faulty shared commit so collaborators can follow ordinary history.
A faulty production change has already been merged. A revert preserves the history while recording its correction, allowing collaborators to update normally. Resetting a shared branch moves its reference and can discard or rewrite others’ expected ancestry; reset modes also differ in their index and working-tree effects.
Common mistake
A destructive reset can discard local changes or rewrite published ancestry.
Verify the behavior
Inspect history and the resulting behavior, including dependent later changes.
Interview exercise
Undo a production regression.
Answer and reasoning
Create and validate a revert or targeted fix, then deploy it through the normal release path.
Continue learning
Compare the scenario with the Git and CI/CD interview questions and test your understanding with the Git and CI/CD MCQs. For terminology and implementation details, consult the reference material.