2

I have a feature branch, let's call it "myfeature," that I've been working on. Client wanted me to put it on the test site, so I merged it into the "staging" branch and pushed to origin. Since then, I've made several commits on the "staging" branch. Today, the client decides they don't want "myfeature" anymore.

How can I undo the merge I did several commits ago? I still have the "myfeature" branch. I basically want to take all the changes that are in that branch and pull them out of the "staging" branch and save "newfeature" for another time.

4
  • Can you rebase the staging branch? In other words, does anyone else have a copy of that branch? Commented Dec 13, 2011 at 14:53
  • 1
    How did you do the merge? Is it a fast-forward merge? Because if its a "true merge" (that's how it's called on the man page), you could try to revert the merge-commit. Commented Dec 13, 2011 at 14:54
  • @svick, Other people do have a copy of the branch, but they are all in sync with the remote, that is, they have done several pulls since the merge Commented Dec 13, 2011 at 14:57
  • @Unapiedra I did the merge using "git checkout staging", "git merge myfeature", "git push origin staging".. does that help? Commented Dec 13, 2011 at 14:58

2 Answers 2

3

You can use git revert to revert a merge, but you have to specify (via the -m option) the parent number of the merge commit that you want to revert to. Say you have a history like this:

c1--c2----------c5--c6--c7
     \--c3--c4--/

The merge commit is c5. You can revert the merge with:

$ git merge -m 1 c5

Normally the master branch is the first parent, so -m 1 usually works.

More info is available here.

Sign up to request clarification or add additional context in comments.

1 Comment

I think @mipadi is trying to say to 'revert the merge', use git revert -m 1 c5. Reference: git-scm.com/docs/git-revert
0

Can't you just revert the merge commit?

git revert <SHA1-OF-MERGE-COMMIT>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.