Is your pride more important than your job?
Also, it's not "Your code," it's "The company's code."
The way you avoid this problem is constructively disagreeing. It seems like you disagreed to the point the other programmer went to the PM to get their input and then a decision was made without you. This suggests a fair bit of dysfunctionality on your team. My speculation is you are not someone who handles confrontation well (perhaps not, something to consider at least).
If you disagree, you should do the following:
- Discuss with the team (as you and your coworker did not seem to do)
- If you can't agree, escalate to a decision maker who can make the decision
Any ideas how to resolve this situation?
Go with what the PM said. Work to improve your relationships with both the PM and your coworker.
Much of work is doing things we don't want to do. Sometimes that means setting aside personal pride.
If you want bonus points here, try to address the problem proactively for the future. Talk with the PM and this coworker along the lines of, "how can we improve communication over subjects like this in the future? I felt like you went over my head and forced changes on me. Can we make a process to avoid this?" or something like this.
UPD I wasn't told about any problems on my side before this happened. These changes don't address any specific problems, it's just a "slight refactoring". The problem is that this refactoring is not small at all, and it breaks things.
If someone breaks things, then the normal response is to discuss with them:
- "Hey, this refactor broke a bunch of things, we need to revert it until it addresses them"
- did you not have any tests?
- Do you have API versioning if this was another internal API
- Make changes
- Review them (you do have code review?)
- Address the concerns
Instead you could also approach this with the coworker and the PM, "hey this refactor you did caused X, Y, and Z to occur too. What is the plan to fix those and how can we prevent this from happening with future refactors?"
Another option is to talk with your manager and ask how they think you should proceed. If your manager is remotely competent they will ask what your efforts to resolve this situation have been.
Also, consider that you seem to not know why this change was made. Maybe it was to fix a bug somewhere else that was affecting customers. Maybe it's because they hate you. Who knows? Going to war over this without knowing that has some serious potential to make you look bad.
If you want to go quit because someone else made changes to your code, by all means do.