0

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...

  • Did you remove the original branch `b1`? If not, your changes prior to `mc1` should still be present in `b1`, allowing you to revert `b2` safely – wcarhart Aug 28 '19 at 22:20
  • How to revert a commit: https://code.likeagirl.io/how-to-undo-the-last-commit-393e7db2840b – wcarhart Aug 28 '19 at 22:22
  • @wcarhart No branches have been deleted. I haven't merged in either branch, and will be merging b1 into master around the same time as b2, well as soon as I verify both, they will both be merged in. – GRONT-Chomper Aug 28 '19 at 22:25

1 Answers1

0

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.

wcarhart
  • 2,685
  • 1
  • 23
  • 44