What I think happened is one of my ships must have hit a terran patrol ship by accident and triggered the whole thing.
I'd be inclined to agree with this, I can't see much of any other way that the situation could have come to pass if your rep was 30 at the start of all this.
As for how to get them to stop being hostile, you can't really do anything there (there was a handy mod for this but it hasn't worked for a while now). They will calm down on their own though after some time. Just stay away from the Terrans for a while so that combat doesn't keep happening and they'll go back to non-hostile after a little while.
As for how to actually do the above? Well, if you're based in Getsu and Asteroid Belt... Well, shit, that's a tough one. Are a lot of the Terrans over there hostile to you, or just a couple of patrols? It's not like you're at war with Terra or anything, but if there are too many of them showing red in sectors where your stations are based then avoiding conflict could be difficult.
The standard way to handle this is to just wait it out and 30-60 minutes later it isn't a problem anymore. Eg: You've pissed off a station and it's red and hostile now, just stay away from the station for a while and it resets. I'm not certain of how you'd manage that when the situation is reversed. Thankfully, I've never been in this position.
If we weren't talking about Shipyards here I'd be tempted to just tear down the stations in question and re-build them later once the bullshit has blown over, but that's really not an option when discussing things of that scale.
And yeah, you're doubly fucked that this is happening with Astroid belt, that's some really bad luck considering its particular location.
If you can avoid combat for long enough, the hostiles will reset and become friendly again... Good luck!
Now, prevention. There you do have a valid path ahead of you. The only way you could have gotten into this would have been if your forces were shooting at someone, so it'll be KHA or XEN. In Getsu Fune XEN are the more likely culprit anyway. Easy fix for this problem, bring your war machine to Getsu Fune and pacify the shit out of the whole place, then place defence stations at the gates to The Void and Savage Spur. If you make Getsu as safe as possible then you can avoid unhappy accidents entirely. With no XEN, that just leaves periodically nuking the KHA installations once in a while, which is trivial enough as you know.
Are you hostile or at war with any of the Commonwealth factions too? That could complicate things a lot if so.