Hi there
it means to act with good morals and character and to deal with situations with integrity ,so that you will not feel ashamed later.
The expression reflects your own moral ethics and self-discipline so that one does not experience shame due to excessive behavior or indulgence after the event.
Specifically it refers to having sex with somebody that you later regret, although it can be applied to any behavior.