You say f’(x)=2x-y this implies y doesn’t equal f(x)
i assume you mean y’=2x-y which is in the form y’+Py=Q
I(x)=e^(integral P dx)
This is a first order linear nonhomogeneous differential equation. It has a few approaches but one specific formula works perfectly.
y=1/I(x)[integral Q(x)I(x) dx + C]
when you solve that, you will have your answer