Good evening,
we've ran into the following git issues on one of our intern projects. We've got two branches, main and feat/smth and both have diverged during development. There was a pull request created from feat/smth to main which showed those conflicts. Those conflicts were resolved using the graphical tool of GitHub, basically performing a merge from main to feat/smth in order to fix the conflicts. This merge was faulty and resulted in corrupted files which were not noticed for now.
Therefore, the feat/smth branch was merged (using GitHubs Pull Request) into main where the errors were found. In order to revert the changes, the students ran a git revert on the merge commit on main and pushed all these changes. Now, the issue is that we would like have the changes from our feat/smth branch and merge them "again" into main. Obviously, that does not work because the commits are already merged and therefore present on main.
Let's assume that we don't want to force push because a lot of other developers already checked out the code and continued working. My first thought was to revert both merges locally using git reset -m <commit_sha> and re-perform the merge. During the merge, I've "avoided" the errors from the very first merge attempt. I've stashed the files, pulled the feat/smth branch and applied my stash. Using this approach, we've got the correct changes from our merge, but all other changes on the branch aren't applied anymore, as they are still reverted on the main branch. The commits of our feat/smth branch are already present on main and were reverted. The only change we introduce using this attempt are the correct changes from the merge.
And that's where I'm basically stuck. What is a proper way in order to undo a merge pushed to main and re-apply the original changes from the branch? My first thoughts were cherry picks, although that might be cumbersome with a lot of commits (and might result into a lot of merge conflicts?) or to take a "hard copy" of the correct version of the branch and just copy paste them onto the main branch. However, this might result in non-wanted changes, as well. The later approach might get tricky in case that changes were made to main already. The author has to carefully check all the changes and distinguish between those from the feat/smth branch and the ones from the main branch. In addition, copy paste doesn't feel like it's the proper "git way". Any ideas? I really don't know how to solve that the "git way".
I've made a drawing of the git history, as well for illustration purposes.
Thanks a lot! I'm curious about the approaches.
