The Holy Roman Emperor had but a dozen
domains left under his direct
Here but means "only".
Drink everything you want but alcohol.
Here it means "except": everything except alcohol. It means "except" when two things are mentioned, both the whole (everything) and a part (alcohol). In the first example above, no whole was mentioned, so that but had to mean "only a dozen domains"—but not so here.
She was all but killed by the
Here it means "except" as well. The "whole" is all. Then we get "all except killed"; this means that the assassin came very close to killing her, but he did not actually kill her. She might be badly wounded, or she might have quickly ducked behind the statue when he fired. "Short of" has roughly the same sense.
All senses of but probably come from some older sense similar to "only" or "except": if the "except" cases came from "only not" and "not" had been dropped somewhere along the way, it would all be logical; but I'm not sure whether that is how it came to be as it is now.
She left me behind at the gas station,
except she came back later out of
In informal language you might hear this; you could even use only instead.
The funny thing is that you can see a similar development in some other languages. In Dutch, maar means both "but" as in "I like you but you stink" and "but" as in "I have but (only) two socks left". But if you wanted to use maar with the sense "except", you'd need a negation (which is only logical).