M.S.
You're right--spanking would not make sense to teach her not to hit. Take heart in that she is normally well behaved, as you say. On the rare occasion my toddler hits, we say, "No, we don't hit Mommy," and then ask her to say sorry and give a gentle touch. She used to hit on a regular basis but it doesn't happen much, anymore, as she gets older. Also, depending on how verbal your daughter is/as she becomes more verbal, you can also start talking to her about her feelings, asking how she feels, or having empathy: "I bet you get pretty angry when I tell you no." We used to give my daughter other options for when she was angry, sad, etc.--clapping her hands, jumping up and down, hitting the drum, so that she could use her body to express these emotions in a less interpersonally violent way! Now that she's talking we focus on using words.
Hope this helps. I'll be interested to see others' responses.
PS--Take a lot of deep breaths and remember she is still learning.