1

I have the following git Branches

  • Feature Branch
  • Production Branch

I merged my Feature Branch with the Production branch and after this merge, there were some issues on Production hence I used the GitHub Revert feature and created Revert-Feature-Branch which was then Merged with Production.

Now, I have fixed the bugs in my Feature Branch and I am trying to merge that Branch with Production but I am not getting all the changes that were done by me, I am getting only the changes done for the fixes. (which is acceptable since the commits are already merged with the Production Branch.)

is there a way to get my original code from the Feature Branch to merge into the Production branch as a new commit without Resetting the Production Branch?

Thank you for the help.

Note, I have already done some research and read the following answer: How to revert a merge commit that's already pushed to remote branch?

which did not help.

Akshay Khale
  • 8,151
  • 8
  • 50
  • 58
  • 1
    You might have to [revert the revert](https://stackoverflow.com/questions/1078146/re-doing-a-reverted-merge-in-git) – Jan Wilamowski Sep 09 '21 at 07:07
  • Yes, That's what I did, It created `Revert-Revert-Feature-Branch` Branch and then I merged the `Feature Branch` with fixes into the `Revert-Revert-Feature-Branch`. Please post this as an answer so that I can accept it and close the question. Thank you!!! @JanWilamowski – Akshay Khale Sep 09 '21 at 07:27
  • Does this answer your question? [Re-doing a reverted merge in Git](https://stackoverflow.com/questions/1078146/re-doing-a-reverted-merge-in-git) – Jan Wilamowski Sep 09 '21 at 07:48

2 Answers2

3

A simple revert-the-revert might not work since you have fixes on the top, so you might have to rebase after reverting the revert

feature: branch that you merge into production
feature-fixes: branch that contains the fixes
feature-reverted: contrains the reverted feature
feature-reverted-revert: contains the reverted revert

so you might have to do

git checkout feature-fixes
git rebase feature-reverted-revert
git checkout feature-reverted-revert
git merge feature-fixes
git checkout feature
git merge feature-reverted-revert

now you can merge the feature branch into production after verifying that everything is correctly in place

Aurangzeb
  • 1,537
  • 13
  • 9
0

If the feature branch is a straight line, then you need to fool git into believing that the original revisions were never merged in the first place. It might seem like it's difficult to do but that's not the case. First, find the last common ancestor between both branches. Then check out this revision. Then reapply (cherry-pick) all revisions of the feature branch. To git, it's like these new revisions were never applied on the branch.

git merge-base the-target-brsnch the-feature-branch
git checkout -b temp that-id #using a new branch temp
git cherry-pick HEAD..the-feature-branch

Of you try to merge the resulting branch into the target branch, unit should carry all changes this time.

eftshift0
  • 26,375
  • 3
  • 36
  • 60