Git
Version Control
Commit Revert
Software Development
Git Commands

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.

Browse interview questions

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:

  1. commit A introduces a feature or fix
  2. commit R reverts A
  3. you now want the behavior from A back

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:

bash
git log --oneline --decorate -n 30

Look for the revert message and note its hash.

Revert the Revert Commit

Once you have the revert commit hash, run:

bash
git revert <revert_commit_hash>

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.

bash
1git status
2# edit conflicted files
3git add path/to/resolved-file
4git revert --continue

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.

bash
git checkout -b restore-feature-x
git revert <revert_commit_hash>

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:

bash
git show --name-status HEAD

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:

bash
git 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 revert on 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
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track 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.

Browse interview questions

All Rights Reserved.