Direct answer
Decide how you would undo a release before you ship it, and write that decision down as part of the release, not during the incident. Pick the rollback unit, the smallest set of commits or changes you would reverse, then rehearse the inverse on a safe branch. Git revert creates a new commit that reverses an earlier one, and the Git documentation warns specifically that reverting a merge commit has consequences for later merges (F082). Git can reverse a code change. It cannot reverse a database migration that already ran, an external call that already fired, or user data that already changed.
Record what Git cannot undo next to the plan. The rehearsal and the list of external effects are the parts teams skip, and they are the parts that decide whether a rollback works at 2 a.m.
Why the plan has to exist before the release
A rollback decided during an incident is a guess made under pressure. The team is looking at a symptom, the clock is running, and the tempting move is to revert the most recent thing that changed. That instinct can revert the wrong unit, or revert the right unit and leave the damage in place because the damage was not in Git.
Planning ahead changes the decision from a guess into a lookup. The release record already names the rollback unit, the inverse action, and the effects Git does not cover. The incident becomes a sequence of executed steps rather than a debate.
There is also a correctness reason to plan early. Some release shapes make the inverse expensive or impossible. A change that rewrote history, a migration that cannot be reversed, or a merge whose revert complicates the next merge all become clear only when someone asks the question before shipping (F082).
Define the rollback unit
The rollback unit is what you would reverse as one action. It can be a single commit, a release tag’s range, a feature flag, or a deployed artifact. Naming it forces a choice that otherwise stays vague.
The unit should match how the release actually reached consumers. A library released under a tag is reversed by a new version that reverts the change, because released versions are immutable. An application deployed as one artifact is reversed by redeploying the previous artifact. A change gated behind a flag may be reversed by turning the flag off, which is faster than any Git operation.
| Release change | Rollback unit | Inverse action | Owner |
|---|---|---|---|
| Library bug fix released as 2.4.1 | Revert commit on main, released as 2.4.2 | Revert commit plus patch release | Library owner |
| Service deploy of 40 commits | Redeploy previous artifact | Roll artifact forward again after fix | Service owner |
| Single feature behind a flag | Flag state | Disable flag, no code change | Feature owner |
| Large merge into main | Revert of the merge commit | Depends on later merges (F082) | Integration owner |
The library row depends on the immutability rule. The versioning specification says a released version must not be modified, so the inverse of a bad release is a new release, not an edit (Semantic Versioning 2.0.0, official). The mechanics of tagging that new release are in annotated release tags.
Identify external state changes
This is the section that saves the most time in a real incident. List everything the release changed outside the repository, because Git revert will not touch any of it.
External effects include database rows written under a new schema, rows created by a migration, messages published to a queue, files written to object storage, third-party records created through an API, caches warmed with new shapes, and emails or notifications already sent. None of these reverse because a commit was reverted.
| External effect | Git coverage | Separate recovery step | Risk |
|---|---|---|---|
| Rows written with a new required column | None | Forward-fix or backfill script | Data shape mismatch on rollback |
| Migration that added an index | None | Migration tooling, if reversible | Rollback may leave the index, or fail without it |
| Events published to a queue | None | Consumers must tolerate old and new shapes | Duplicate or malformed events |
| Files written to object storage | None | Cleanup job | Orphaned objects |
| Third-party records via API | None | Reconciliation or manual correction | External state outside your control |
| Cache entries in a new format | None | Cache invalidation | Stale reads after rollback |
The migration row deserves care, but the detailed safety guidance for database migrations is out of scope here. What belongs in this article is the boundary: a revert changes code, and any data the old code wrote stays as it was. Treat the migration and the code as separate rollback units with separate owners.
Rehearsal scope depends on the release system and cannot be assumed from Git alone (F084). A team that deploys a single artifact rehearses a redeploy. A team that releases a library rehearses a patch release. The rehearsal has to match the real transport.
Choose the revert or forward-fix path
Not every bad release should be reverted. A revert is right when the change is isolated, the inverse is cheap, and consumers need the old behavior back quickly. A forward fix is right when the defect is small, the inverse is expensive, or the new behavior is mostly correct and only an edge case is broken.
Decide this before shipping by writing the trigger for each path. A trigger names the observed condition that would make the team choose that path, so nobody has to argue about thresholds during the incident.
| Trigger | Chosen path | Verification | Decision owner |
|---|---|---|---|
| Data integrity defect reachable by any user | Revert to last known good | Redeploy previous artifact, verify reads | Service owner |
| Cosmetic defect in one screen | Forward fix in next release | Normal review plus targeted test | Feature owner |
| Performance regression above threshold | Revert or flag off | Measure against the recorded baseline | Performance owner |
| Security defect with a known exposure | Revert plus incident process | Revert, then confirm exposure closed | Security owner |
| Migration already applied, code is wrong | Forward fix the code, keep migration | Verify code against existing data | Data owner |
The security row is a judgment about exposure, and this article does not provide exploit details. The release mechanics are the same as any other revert; the incident process around it is separate.
Rehearse the inverse change
A revert you have never run is a revert you cannot trust. Rehearse it on a branch or in a staging environment that mirrors the release shape.
The rehearsal answers concrete questions. Does the inverse apply cleanly, or does it conflict with later commits? Does the code compile and pass its checks after the inverse? Does the release transport accept the inverse, whether that transport is a redeploy, a patch release, or a flag flip? How long does the whole sequence take?
Define and rehearse the inverse change, then list the external effects Git cannot restore (F084). The rehearsal is what converts the inverse from a theory into a procedure with a measured duration. That duration is the input to the incident decision, because a rollback that takes forty minutes is a different choice from one that takes four.
Do not ship an unrehearsed inverse change (guardrail). If the rehearsal reveals that the inverse does not work, that is a release blocker, and the honest options are to fix forward or to delay the release until a working inverse exists.
Check merge and follow-up behavior
Reverting a normal commit is straightforward. Reverting a merge commit is the case the Git documentation singles out, because a merge commit has more than one parent and the revert does not simply undo it in place (F082).
The practical consequence is about what happens next. If a merge is reverted and later you want to bring that work back, the reverted content can interfere with a future merge, because Git may see the content as already merged and reverted. The exact behavior depends on the repository’s history and must be analyzed for that history (F082). There is no universal rule that makes a merge revert simple.
The Git revert documentation describes options for working with multiple parents, and the general guidance is to understand the topology before reverting a merge (Git revert, official). Reviewing the topology with log and show is the same inspection discipline as inspecting an annotated tag target.
| Revert shape | Later-merge concern | What to check | Follow-up |
|---|---|---|---|
| Single-parent commit | None expected | Normal inverse verification | None |
| Merge commit | Re-introducing the work later can conflict (F082) | Topology and parent order | Plan re-land procedure |
| Squashed merge | Underlying commits are not individually revertible | The squash commit is the unit | Revert the squash, then re-land |
| Rebased branch | Original commits may be orphaned | Which commits are reachable | Confirm the branch state |
For teams that squash, the squash changes what a revert can target. Atomic commits that stay revertible explains why keeping changes revertible affects rollback options, and the merge mechanics appear in resolving merge conflicts by behavior.
Run the relevant verification scope
The inverse change needs its own verification, because it is a code change like any other. Run the checks that cover the reverted behavior plus the release gate.
The scope is usually narrower than the original release, because you are restoring known-good behavior rather than introducing new behavior. Narrow does not mean none. A revert that skips the branch gate can ship a build that does not compile, which turns an incident into two incidents.
Mapping changed code to checks is the method for choosing the relevant tests, and triaging flaky tests before rerunning keeps a rerun from being mistaken for verification. A green pipeline is not proof the rollback restored the right behavior, which is the broader warning in false success from passing tests.
Ask Claude Code to list unrestored effects
Before shipping, ask Claude Code to enumerate what a revert would not cover. A useful prompt names the change and the rollback unit:
If we revert the change set between tag
v2.4.0andv2.4.1, list every effect that reverting the commits would not restore. Include database writes, external calls, published events, caches, and anything the code wrote outside the repository.
Review the list for completeness rather than precision. Claude Code can read the diff and find calls to external systems, migration invocations, and queue publishers. It cannot know whether a particular external system was reachable in production or whether a queue consumer tolerates old shapes. Those facts come from the team that operates the system.
This is the same division of labor as other review steps in the batch. Claude Code widens the search over the repository. A person who operates the system owns the judgment about external state. The generated list is analysis, not a rollback guarantee, and the sample release procedure in the official documentation is an example to adapt rather than a required workflow (F083).
Record the rollback decision tree
Write the plan where the release is tracked. A decision tree that lives in someone’s head does not survive an incident.
| Trigger | Path | First action | Verification | Owner |
|---|---|---|---|---|
| Data integrity defect | Revert to previous artifact | Redeploy last good | Verify reads, confirm no new bad rows | Service owner |
| Performance regression | Disable feature flag | Flip flag off | Measure against baseline | Performance owner |
| Cosmetic defect | Forward fix | Normal release train | Targeted test plus review | Feature owner |
| Security exposure | Revert and escalate | Redeploy last good, escalate | Confirm exposure closed | Security owner |
Each row should also carry the external recovery step from the effects table, because that step is the part Git does not perform. A rollback plan that only names the Git action is half a plan.
The release-wide record that holds identity, tests, notes, exceptions, and this rollback unit is covered in verifying the release candidate, and the entry consumers read is in consumer-facing changelog entries.
Worked example: planning the rollback for a validation change
Suppose a release tightens validation so a previously accepted empty region now fails. The change is a single commit on main, released as a library version 2.5.0, and it also triggers a background job that records validation outcomes to an analytics table.
Rollback unit: the single validation commit, because it is the only behavior change in 2.5.0.
External effects: the analytics table now receives rows with a new outcome value for rejected regions. Reverting the code stops new rows from having that value, but the rows already written keep it. Consumers of the analytics table must tolerate the new value or the data needs cleanup.
Path choice: a consumer that requires region to be accepted is broken now, so the trigger is a compatibility defect. The path is a revert released as 2.5.1.
Rehearsal: on a branch, revert the commit. It applies cleanly because no later commit touched the validation. Run the validation suite and the branch gate. Time the patch release process at eleven minutes in staging.
Inverse action: revert commit on main, release as 2.5.1 with a changelog entry explaining that validation reverted to the previous behavior.
Unrestored effect: analytics rows already written keep the new outcome value. Record a reconciliation step for the analytics owner.
Derived arithmetic for exposure: the release ran for 3 days before the defect was reported. Validation rejections recorded in the analytics table during those 3 days = 1,240 rows. Rows written before the release = 0 with the new value. Rows needing reconciliation if consumers reject the new value = 1,240. This arithmetic sizes the cleanup; it is not a defect count or a severity measure.
The concrete win is that the team can reverse the change in about eleven minutes with a procedure they rehearsed, and they know the analytics table needs a reconciliation decision. The concrete loss is that the 1,240 rows do not disappear when the code reverts, and if the analytics consumers are strict, the rollback is incomplete until that data is handled.
Practical checklist and runbook
Use this sequence before every release. On a small change it takes minutes. On a change with external effects it is the most valuable time in the release.
- Name the rollback unit. The commit, tag range, flag, or artifact you would reverse.
- List external effects. Database writes, external calls, events, caches, notifications.
- Assign owners. Each effect and each path needs a person, not a team name.
- Choose revert or forward fix. Write the trigger that would decide it.
- Check merge topology. If the unit includes a merge commit, analyze later-merge behavior (F082).
- Rehearse the inverse. Apply it on a safe branch and run the relevant checks.
- Time the transport. Redeploy, patch release, or flag flip, with a measured duration.
- Record the decision tree. Trigger, path, first action, verification, owner, external step.
- Attach the plan to the release record. The plan travels with the release, not with a person.
| Gate | Pass condition | Failure response |
|---|---|---|
| Unit named | One reversible unit is written down | Define the unit before shipping |
| Effects listed | Every external write has a row | Enumerate external calls in the diff |
| Path chosen | Each trigger names a path and owner | Assign triggers and owners |
| Merge analyzed | Merge units have a later-merge plan | Analyze topology, or pick a different unit |
| Inverse rehearsed | The inverse applied and passed checks | Fix forward or delay the release |
| Tree recorded | The plan is in the release record | Write it down where the release is tracked |
The practical implication is that rollback planning is cheap before a release and nearly impossible during one. The plan does not make a release safe. It makes the response to a bad release a procedure instead of an argument.
Concrete win, honest loss, and next decision
Win: In the validation example, the release carried a rehearsed inverse with an eleven-minute measured transport and a named owner for the analytics reconciliation. The incident response is a lookup, and the code side of the rollback is a patch release the team has already practiced.
Loss: The rollback is incomplete by construction. The 1,240 analytics rows written during the three exposed days retain the new outcome value after the code reverts. If the analytics consumers cannot tolerate that value, the incident is not closed by the revert, and the missing piece is a data decision that Git cannot make (F084).
Implication: Use this planning for any release that writes outside the repository, touches shared data, or cannot be trivially redeployed. For a pure, stateless code change behind a flag, a one-line rollback note may be enough. The effort should scale with how much external state the release can change.
Connect the plan to the rest of the batch
A rollback plan is the inverse of the release disciplines in this batch. Deciding the major, minor, or patch increment classifies the revert release, and annotated release tags pins the good version you would return to.
Backporting a hotfix with cherry-pick is the forward path for a fix on a supported line, and consumer-facing changelog entries tells users whether the rollback requires action. Verifying the release candidate is the record that should already contain this rollback unit.
For the commits the plan reverses, atomic commits that stay revertible is the property that makes a clean revert possible, and commit messages that encode change intent helps a reviewer confirm the unit is the right one. Resolving merge conflicts by behavior matters when the unit includes a merge, and choosing a rebase or merge policy explains why replayed history complicates an inverse.
When you need to find the change that caused the problem, hunting the regression with git bisect locates the commit, and inspecting a suspicious commit is covered by the same tooling as annotated tag targets. Guardrails against destructive git reset is the boundary around rewriting history as a substitute for a revert (guardrail).
Verification of the inverse runs on the same evidence as any change. Mapping changed code to checks, triaging flaky tests before rerunning, and false success from passing tests define what a green rollback run does and does not prove.
Release mechanics around the plan appear in defining branch protection merge checks and recovering failed merge-queue groups. For the code-review pressure that a rollback request creates, see the code review bottleneck, and for preserving the reasoning across a shift, see session handoff with team context.
Data gap and future update
The Git documentation confirms that reverting a merge commit has consequences for later merges and that the exact behavior depends on the repository’s history (F082). The official Claude Code best practices describe a sample release skill that updates changelogs and tags commits, and the documentation presents it as an example procedure rather than a rollback guarantee or a required workflow (F083). None of the cited sources provides a measured rollback success rate, a benchmark comparing revert with forward fix, or data on how often external effects make a revert incomplete. No such figure is claimed.
The rehearsal scope is explicitly dependent on the release system and cannot be derived from Git alone (F084). That means the timing numbers in the worked example are illustrative for one hypothetical team, not a general figure. A future update could add measured transport times if a team publishes them with method and environment.
Rolling documentation can change. Recheck the cited Git and Claude Code pages before relying on specific wording, and keep the caveats if the text shifts. Until measured evidence exists, treat this method as a reviewable planning practice rather than a proven reduction in incident duration.
One AI API Key option for OpenAI-format agents
Claude Code uses an Anthropic-format route, so the One AI free model IDs are not a Claude Code model source. The packet records Claude IDs as unavailable on 2026-11-27.
For a separate OpenAI-format agent, One AI API Key provides https://api.oneaiapikey.com/v1, one key, and 46 live free IDs. That option concerns a different client and request format, not a workaround for Claude Code authentication. Check the free model list and eligibility details before choosing an agent route.
FAQ
Does git revert restore my database or external services?
No. Revert creates a new commit that reverses code changes. Data already written, messages already published, and external records already created stay as they were (F084). Those need separate recovery steps that the rollback plan should name.
Why is reverting a merge commit different?
A merge commit has multiple parents, so the inverse is not a simple undo of one line of history (F082). The Git documentation warns that reverting a merge has consequences for later merges, and the exact behavior must be analyzed for the repository’s own history rather than assumed.
Is history rewriting a valid rollback plan?
No. Rewriting published history changes the identity of commits and tags consumers may already rely on (guardrail). The rollback plan should use a new commit or a new release. For the boundaries around rewriting history, see guardrails against destructive git reset.
When should I forward-fix instead of revert?
Forward-fix when the inverse is expensive, when the defect is narrow, or when re-landing the reverted work later would be costly. A merge whose revert complicates future merges is a common forward-fix case (F082). Write the trigger down before the release so the choice is not debated during the incident.
What does the rehearsal actually need to cover?
The inverse applying cleanly, the code passing its checks after the inverse, and the real release transport accepting the result. The scope depends on the release system and cannot be inferred from Git alone (F084). Timing the transport gives you the duration input for the incident decision.
More Claude Code troubleshooting
- Claude Code Deterministic Tests: Control Time and Randomness
- Claude Code Contract Tests: Check API Expectations
- Claude Code Snapshot Review: Inspect the Diff, Not the Green
- Claude Code Property Tests: Generate Edge Cases
- Claude Code Mutation Testing: Find Weak Assertions
- Claude Code Test Fixtures: Isolate Shared State
- Claude Code Minimal Repro: Shrink the Failure
- Claude Code Debug Log: Separate Facts from Hypotheses
- Claude Code Async Races: Make Scheduling Deterministic
- Claude Code Memory Leaks: Compare Allocation Snapshots
- Claude Code Complexity: Refactor Hotspots, Not Metrics
- Claude Code Duplication: Choose Reuse or Independence
- Claude Code Static Analysis: Baseline the Noise
- Claude Code Dead Code: Prove Usage Before Removal
- Claude Code Git Stash: Recover Work Without Dropping It
Sources
- Official: Git revert, supporting the warning about merge-commit reverts and later-merge consequences (F082).
- Official: Git tag, supporting the tagged good version a rollback returns to (F089 context).
- Official: Git bisect, supporting locating the change that caused the problem.
- Official: Semantic Versioning 2.0.0, supporting the immutability of released versions that makes a revert a new release.
- Official: Claude Code best practices, supporting the sample release skill and the instruction to adapt it (F083).
- Official: Git show, supporting inspection of the commits a rollback unit contains.