How do you force OS X to re-detect displays? I use my MacBook at work and at home. Whenever I switch between work and home,  every now and again I get bug whereby the Mac thinks an external monitor is still plugged in, even if it's not.

This means when I go to plug in either my work or home monitors, one of them doesn't work as OS X still thinks there is a different monitor plugged in.

The only way I've been able to fix this is to restart, but I was hoping there was a quick way to fix this through a terminal command or something.

Note that System Preferences > Displays > Option + Detect Displays does not work.
Go into System Preferences->Displays and when there (doesn't matter which tab) press the 'Option/ALT' key and you'll see 'Detect Displays' where the 'Gather Windows' button is (on 10.13.x) or simply in the lower right on 10.14.x (as this page doesn't have a 'Gather Windows' button.)