I have merged a development branch into master. But it was discovered the merge introduced bugs to master, so I reverted my commit. I have fixed the bugs, but when I try to pull from master into my branch, I see that this will delete many of my changes as Git probably determines master to be more up-to-date than some files on my branch due to revert.
How can I merge all my work, including both bug fixes and other content without losing anything?
Ideally, I would like to tell git to treat my branch as the newest content because no new commits to master were made since my revert.
To clarify: my original merge included modifications to existing files and some new files. When a bug was found, I've reverted everything. The fix affected only several lines of code. Now, when I try to create a merge request or just pull from master, Git recognizes only these fixes as new content which should be merged, and everything else as old content which should be deleted.
This is the normal consequence of reverting a merge commit. So, for example, suppose we have this:
We now merge
featureintomain:We now revert the merge:
We then continue working on
feature:We now attempt to merge
featureintomainagain and we are horrified to discover that most of it is not arriving intomain! What's happening?What's happening is that for all the commits that were already merged (X and Y in the diagram), the merge train has left the station. The
reverthas reverted the state ofmainbut the topology ofmainis unaffected; thanks to the merge, X and Y are now onmain. Those commits have thus already been merged intomainand they can never be merged again.Solution — well, there are a number of ways around this situation. The easiest is probably to make a whole new branch off of
mainat the same point wherefeaturebranched off it, andgit cherry-pickthe commits offeatureonto it:The commits
Xnew,Ynew, andZnewwill look like X, Y, and Z, but they are different commits and so they can be merged intomain. Thus, mergingfeatureNewintomainwill now have the desired effect.