And prevention wouldn’t require Bruce Willis to blow it up with nukes, like the DART mission all you’d need is to hit the space rock with a fast moving, small probe and alter its course by a millionth of a degree far enough out, could be the difference between hitting a city, landing in the ocean, or not hitting earth at all.
I'm quite sure it wouldn't work but was an interesting idea.
You probably wouldn't want to nuke it, because you risk buck shotting the earth with a cloud of asteroids. Having a vectored nuclear rocket also allows you to change your trajectory if your initial calculations are off.