I also have 2 monitors and I used to have this problem too! I also use spaces, and all the spaces would be switched over, so I'd have to do a lot of switching.
Here's what works for me, if I dock my laptop and find that the screens are reversed:
1. Unplug monitor A, wait for screens to stabilize.
2. Unplug monitor B, wait for screens to stablilize.
3. Plug in monitor A, wait for screens to stabilize.
4. Plug in monitor B, wait for screens to stabilize.
And that fixes it every time. My "default" monitor is set to be my laptop's monitor. Try reversing the roles of A and B if it doesn't work.
If you use spaces as well — I also find it helps to have an empty space as the first space for each monitor.
Here's what works for me, if I dock my laptop and find that the screens are reversed:
1. Unplug monitor A, wait for screens to stabilize.
2. Unplug monitor B, wait for screens to stablilize.
3. Plug in monitor A, wait for screens to stabilize.
4. Plug in monitor B, wait for screens to stabilize.
And that fixes it every time. My "default" monitor is set to be my laptop's monitor. Try reversing the roles of A and B if it doesn't work.
If you use spaces as well — I also find it helps to have an empty space as the first space for each monitor.