giving a bit of a slap or small whack as a one off case is fine, as long as your child does not get hurt.
but whatever the situation, from a personal experience, i have realised that a direct talk almost always helps, and also spares us the guilt that accompanies hitting.