joe-tripodi
joe-tripodi

Reputation: 48

Affects of removing a merge commit from a feature branch in a feature branch that will both be merged in

In short, I have merged in changes from a feature branch onto my current feature branch, and have pushed the merge remotely, creating a merge commit with the changes I merged in. Now, the problem is, I didn't need these changes. Also, these changes have broken my builds, because I will need to merge in changes from other projects on my current feature branch. I want to avoid doing this, so I want to revert the merge commit.

Two feature branches, b1 and b2.
Merged b1 into b2, creating merge commit mc1, on b2.
Want to revert mc1 on b2.
Afraid revert mc1, will affect the merge of b1 into master staging.

I am afraid because I feel like the revert, will obviously have the changes that remove the stuff I merged in from b1, which could remove those changes from master once both branches have been merged into master...

Upvotes: 0

Views: 148

Answers (1)

wcarhart
wcarhart

Reputation: 2783

Because you haven't removed your previous branch b1, you should be able to safely revert commits on b2 without losing any changes that were present on b1.

You can revert commits with:

git revert <commit hash>
git checkout <current branch>

Read more about reverting commits here.

As for conflicts with master, master will only have changes that are merged in. If you merge only b1 into master, master will have the changes from b1. If you merge only b2 into master, master will have the changes from b2. If you merge b1 and b2 into master, you may have to resolve any merge conflicts that arise, but master will then contain the resolved changes from b1 and b2.

Upvotes: 0

Related Questions