How to Revert a Git Merge (Without Breaking Everything)

VuVu
1 min read

So you’ve just merged a branch into staging, and now you want to undo it? Don’t worry — we’ve all been there. Maybe the feature wasn’t ready, or maybe it caused issues you didn’t expect.

Here’s a super simple guide to revert a Git merge safely.

💥 The Situation

You have a feature branch called feat/new-feature, and you merged it into staging.

But now you want to undo that merge, and bring staging back to the way it was before.

Step-by-Step: Revert the Merge Commit

  1. Find the Merge Commit

Run this command to see recent commits:

git log --oneline

Look for the merge commit message like:

abc1234 Merge branch 'feat/new-feature' into staging

Copy the commit hash (abc1234 in this case).

  1. Revert the Merge

Now, run this:

git checkout staging
git revert -m 1 abc1234

The -m 1 tells Git: “keep the first parent of the merge” (which is usually your base branch, like staging).

This will create a new commit that undoes the changes from the merge.

  1. Push Your Changes

    Once the revert is created, just push it:

     git push origin staging
    

    And that’s it — your staging branch is now back to how it was before the merge 🎉

0
Subscribe to my newsletter

Read articles from Vu directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Vu
Vu