Revert a specific commit from a merged branch that has already been pushed
Asked Answered
D

1

7

I was just reading the post below and I had a question I was hoping someone would know the answer to.

How to revert a merge commit that's already pushed to remote branch?

So I know that I can completely revert a merge commit from my master by specifying its parent branch in the git revert -m command. My question is can I revert a single commit from that merged branch rather than the entire branch.

For example I branch from master to feature_1 branch. I make 14 commits on the feature_1 branch and merge back to my master, which I then push.

How would I go about removing commit 7 of the merged branch from the master while leaving the other 13 in the master. Hopefully its possible and thanks in advance for any replies or comments.

Deodorant answered 17/10, 2016 at 9:2 Comment(2)
possible duplicate of https://mcmap.net/q/45904/-undo-a-particular-commit-in-git-that-39-s-been-pushed-to-remote-repos/4286990.Cautious
Thanks vatsal, I made the assumption that reverting commits that were inside a merge would be harder to do than reverting a normal commit because of the -m option needed when reverting a merge. Turns out I was wrong. Thanks againDeodorant
A
9

Step 1: Identify the <sha1> of the commit you'd like to revert.

Step 2: Do this on the master branch:

$ git revert <sha1>

That will create a new commit that revert the commit identified by <sha1>.

Approach answered 17/10, 2016 at 9:5 Comment(1)
Wow I feel dumb, I just assumed because it was part of a merge I would need to take that into consideration. My apologies for asking such a silly question.Deodorant

© 2022 - 2024 — McMap. All rights reserved.