Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7400971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:20:27+00:00 2026-05-29T04:20:27+00:00

We recently encountered a problem where a merge somehow led to all the changes

  • 0

We recently encountered a problem where a merge somehow led to all the changes leading to one parent being undone in the merge commit, and several commits have been applied after that point. All this has been pushed to our shared origin repository. I want to be able to revert the bad merge and reapply the other change sets. What is the easiest way to do this?

ASCII art example:

    A-B-C-D
   /       \
P-Q         M-X-Y-Z
   \       /
    1-2-3-4

  ---time--->

The commit M has included changes A to D but all changes 1 to 4 were reverted by that commit.

I would like to be able to revert back, eg. to changeset 4, and reapply changes A-D and X to Z, ideally without manually redoing each change.

If this is not possible, I’d like to hear of the best workarounds – eg. maybe branch from 4, merge in D again being careful not to break anything, then manually reapplying X to Z?

(An ideal situation would be to know how to do this using TortoiseGit, although just knowing the command line should allow me to deduce the rest.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:20:28+00:00Added an answer on May 29, 2026 at 4:20 am

    You want to wind up with something whose logical effect is:

    P-Q-1-2-3-4-A-B-C-D-X-Y-Z
    

    There are a couple of approaches. Let’s assume master points to Z right now.


    Revert the merge commit (safest but messier)

    We need to revert the broken merge commit M first. We’ll do that with:

    git revert -m 1 M
    

    Next, let’s re-apply the negated or potentially negated commits:

    git cherry-pick 1
    git cherry-pick 2
    git cherry-pick 3
    git cherry-pick 4
    git cherry-pick A
    git cherry-pick B
    git cherry-pick C
    git cherry-pick D
    

    Now we have this:

    # M reverts some of A..D and 1..4
    # !M undoes the logical effect of the merge
    
        A-B-C-D
       /       \
    P-Q         M-X-Y-Z-!M-1'-2'-3'-4'-A'-B'-C'-D'
       \       /
        1-2-3-4
    

    This is the safest approach because it doesn’t touch any previous history, so no one’s upstream repos will be affected. But it’s also the messiest because it leaves a lot of detritus. Alas, that’s the price you pay for a sloppy merge.


    Throw away the broken history (most dangerous but cleanest)

    This will require getting consensus from everyone that your approach is sound. You will break people’s history, and anyone who has the tainted merge commit M will experience issues if you do it this way. But your history will look cleaner.

    Because you will break the history of any team members who have the tainted commit until they pull down the remote repository and until they reset their local masters to that point, this is the most dangerous approach.

    First, we rewind master back to Q, the last commit without problems.

    git checkout master
    git reset --hard Q       # rewind `master` branch to `Q`
    

    Next, we need to interactively rebase the broken commit sequence.

    git checkout Z         # move to Z
    git branch tmp         # make a branch pointing to Z
    git rebase -i master   # rework this branch onto master
    

    You’ll be presented with a list of commits in your editor that looks like this:

    pick aaaaaaa Commit message one
    pick bbbbbbb Commit message two
    pick ccccccc Commit message three
    # ...
    

    One of these will be the broken merge commit. Delete this line; save and close.

    Git will now apply the commits in the order you asked for, and you will be on tmp. If everything looks good, then reset master:

    git checkout master
    git reset --hard tmp
    

    Now force-push to origin:

    git push -f origin master
    

    The broken history will be removed and master will point to a new history.


    Finally

    You should consider asking your team to use something like nvie’s git-flow to avoid future messiness and prevent snafus.

    Update: It looks like nvie abandoned support for git-flow. However, Peter van der Does forked and is maintaining a version

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently encountered a problem where a value was null if accessed with Request.Form
I recently encountered a problem with my Profile provider: it wouldn't retrieve profiles correctly
I recently encountered an odd problem with RSACryptoServiceProvider.VerifyHash . I have a web application
Developing a heavily XML-based Java-application, I recently encountered an interesting problem on Ubuntu Linux.
I've recently begun learning C# but have encountered an annoying problem. Every variable I
I recently tried to merge a series of changeset and encountered a huge number
I recently encountered a problem in my production database due to MySQL bug. The
I recently encountered a strange problem on my website. Images with æ ø and
recently I've encountered a problem with IE. I have a function function() { ShowProgress();
I've encountered a slight problem recently, or rather a lack of understanding of how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.