How do I un-revert a reverted Git commit?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
If a commit was reverted and you later decide the original change should come back, the usual solution is to revert the revert commit. That keeps history additive and reviewable, which is especially important on shared branches. The command is simple, but conflicts are common if the codebase changed after the original rollback.
Understand the History You Are Reversing
A typical sequence looks like this:
- commit
Aintroduces a feature or fix - commit
RrevertsA - you now want the behavior from
Aback
The standard approach is not to reset history or manually copy code from an old diff. It is to target commit R and revert that revert.
First, locate the revert commit:
Look for the revert message and note its hash.
Revert the Revert Commit
Once you have the revert commit hash, run:
Git creates a new commit that applies the inverse of the revert. In practical terms, that restores the earlier behavior while preserving a clear history of what happened and why.
This is the safest default on branches other people already use.
Expect Conflicts If the Code Moved On
If the surrounding files changed after the revert was created, the restoration may not apply cleanly. In that case, Git pauses and asks you to resolve conflicts.
Do not resolve these conflicts mechanically. The original change may need to be adapted to the current codebase rather than restored line for line.
Use a Branch for Non-Trivial Restores
If the original change was substantial, do the restore work on a dedicated branch and review it like any other change.
That gives you room to:
- resolve conflicts carefully
- run tests
- explain why the rollback is being undone now
- get code review before merging
This is much safer than restoring a large reverted change directly on a busy shared branch.
Know When Revert Is Better Than Reset
If the revert already exists in shared history, git revert is usually better than git reset --hard or force-pushing older commits back into place. Reset rewrites branch history. Revert adds new history.
A simple rule helps:
- on private local cleanup branches, history rewriting may be acceptable
- on shared or published branches, additive history is usually safer
That keeps collaboration simpler and incident timelines easier to understand later.
Validate More Than Git Success
A successful Git operation does not prove the restored behavior still works. After the un-revert, check:
- tests for the restored code path
- compatibility with newer surrounding code
- database migrations or configuration dependencies
- feature flags that may have changed since the rollback
Useful inspection:
That confirms what the new restore commit actually changed.
Recover If You Restored the Wrong Thing
If you reverted the wrong revert commit, the recovery path depends on whether the branch is shared.
- on a shared branch, create another revert to undo the mistake
- on a private branch before push, reset locally and try again
When in doubt, inspect the reflog:
Git usually keeps enough recent history for recovery if you notice the mistake early.
Common Pitfalls
The biggest pitfall is reverting the original commit again instead of reverting the revert commit. That does not restore the old behavior the way people expect.
Another common issue is assuming the original patch can be reapplied cleanly after weeks or months of unrelated code evolution.
Teams also reach for destructive history edits on shared branches when an additive revert would be safer and easier to review.
Summary
- To un-revert a change, usually run
git reverton the revert commit. - This restores the behavior with additive, collaboration-safe history.
- Expect and resolve conflicts carefully if the surrounding code changed.
- Use a dedicated branch and review for non-trivial restorations.
- Test the restored behavior instead of assuming Git success means application success.
Related reading
- How do I undo 'git add' before commit?
- How do I undo 'git reset'?
- How do I undo the most recent local commits in Git?
- How do I update if exists, insert if not AKA upsert or merge in MySQL?
- How do I update or sync a forked repository on GitHub?
- How do I update the password for Git?
- How do I update the password for Git?
- How do I use git bisect?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.