gitmerge

Changes Not Showing After Merging Release Branch into Main Post-Revert of Mistaken PR Merge


I accidentally merged a PR from my development branch (subject-serve-image) into the main branch instead of my release branch (rc/04). I quickly reverted that PR, which created another PR. I merged the revert PR back into main. Afterward, I created a new PR from my dev branch to the release branch (rc/04), which worked fine.

As part of my regular process, I merge my release branch (rc/04) into main periodically. However, when I created and merged the PR from rc/04 to main, it did not show any changes.

What could have gone wrong? What process should I have followed to ensure that the changes from the release branch merged correctly into main?


Solution

  • Let's say your PR was trying to merge commit P. When you accidentally merged it, that meant that main now also contains commit P. Then you did a new PR that reverted P, call it Q and that was subsequently merged into main. So at this point, main now contains P and Q. Note that reverting here did not mean commit P never happened. It means that Q was introduced to reverse the changes in P.

    Next, you created a PR to do what you originally intended, to merge P into the rc/04. Once merged, rc/04 now contains P.

    When you get to the step of merging rc/04 into main, git will look at the set difference. In this case, what does rc/04 bring that I don't already have in main. Since P is present in both rc/04 and main, there are no commits to bring over. Hence, the empty diff.

    You'll want to make sure that main actually represents what you want though. With Q reverting the changes, I'd bet the changes in P are not actually reflected on main.

    One piece of advice is that when you end up reverting a commit and want to re-introduce the changes from that commit, it's best to create a new commit with the changes so that it gets a new ID number. You can achieve that in a couple of ways: straight-up creating a new commit, or amending the commit (git commit --amend) with no change but updates the timestamp (you might need to use --reset-author to force the timestamp to change). Once you have a new commit ID, git will no longer treat the commit as already being merged into main and you'd see the difference you expected.