Lesson Completion
Back to course

Revert a Revert

Intermediate
8 minutes4.7Git

The Hook (The "Byte-Sized" Intro)

You reverted a feature because it had a bug. The team fixed the bug. Now you want the feature back — but git merge feature-branch says "Already up to date." Git remembers the revert and thinks the feature was already integrated. The solution? Revert the revert. It's undo-undo, and it's a real-world pattern that comes up more often than you'd think.

📖 What is Revert a Revert?

When you revert a commit, Git creates a new commit that contains the inverse of the original. If you later want the original changes back, you revert the revert commit — effectively re-applying the original changes while keeping full history.

Conceptual Clarity

The timeline:

1. Original commit: A (adds feature) 2. Revert: B (undoes A — feature removed) 3. Revert the revert: C (undoes B — feature restored!)

Why you can't just re-merge: Git tracks merge history. If you merged feature-branch and then reverted, Git considers those commits "already integrated." A new merge won't bring them back. You must revert the revert to "re-open" those changes.

Real-Life Analogy

Publishing a correction to a correction in a newspaper. Issue 1: the story. Issue 2: the retraction. Issue 3: "The retraction was wrong — the original story was correct." Each edition is published, none are destroyed.

Visual Architecture

gitGraph commit id: "Feature" commit id: "Revert Feature" commit id: "Revert the Revert"

Why It Matters

  • Feature restoration: The only safe way to restore a reverted feature on shared branches.
  • Common scenario: Features get reverted for bugs, then re-enabled after fixes — this is routine.
  • History preservation: All decisions are documented in the commit log.
  • Interview favorite: This scenario tests deep understanding of Git's merge tracking.

Code

bash
# ─── Step 1: Feature was merged and reverted ─── git log --oneline # abc1234 Revert "Add payment feature" # def5678 Add payment feature # ─── Step 2: Revert the revert ─── git revert abc1234 --no-edit # Creates a new commit restoring the original feature # ─── Step 3: Verify ─── git log --oneline # ghi9012 Revert "Revert "Add payment feature"" # abc1234 Revert "Add payment feature" # def5678 Add payment feature # The feature code is back! ✅ # ─── With bug fixes on top ─── # After reverting the revert, apply the bug fix: git cherry-pick <bugfix-commit-sha> # Or merge the fixed feature branch

Key Takeaways

  • Revert the revert = the standard way to restore a previously reverted feature.
  • You can't just re-merge a reverted branch — Git thinks those commits are already integrated.
  • All three steps (original, revert, revert-revert) remain in history — full traceability.
  • This pattern is common in production environments.

Interview Prep

  • Q: How do you restore a feature that was reverted on main? A: Revert the revert commit. This creates a new commit that re-applies the original feature's changes. You can then apply any bug fixes on top. Simply re-merging the feature branch won't work because Git considers those commits already integrated.

  • Q: Why can't you just re-merge a branch after reverting it? A: Git tracks merge history through commit ancestry. When the feature branch was merged and then reverted, Git still considers those commits as part of main's history. A new merge sees "Already up to date" because all the commits are already reachable.

  • Q: What does the commit log look like after a revert-revert? A: It shows three entries: the original commit, the revert commit, and the revert-of-the-revert commit. All changes are documented, providing full traceability of why the feature was removed and why it was restored.

Topics Covered

Git HistoryGit Recovery

Tags

#git#revert#recovery#intermediate

Last Updated

2026-02-13