Good question.
I actually have a multifuel engine. It is basically a diesel that is designed to run on most any fuel including gas. Even with this engine, if I run it on gas, I need to have some oil added to the gas to lubricate the injection pump.
On a traditional diesel, gas instead of diesel would make the engine very hard or impossible to start. Usually if a mistake happens at the pump, the owner fills the tank with gas. There is usually enough diesel in the fuel line to start the engine before it really runs bad. If it continues to run, it could damage the injection pump. The diesel lubricates the pump, but gas doesn't. The injection pump can be one of the most expensive parts on a diesel engine.
If no damage is done to the injection pump, the tank must be drained and the diesel lines drained. Depending on the vehicle, purging the gas from the engine can be challenging. Once the gas is purged from the system, the engine will be back to normal.