Karma is intentional act and it is repeated by habit. Habit is a conviction that doing something is correct. Getting rid of a habit starts with reviewing that conviction, proving it false to oneself, and then mindfully re-educating the mind according to the new understanding. This is taught in the Noble Eightfold Path as right effort
where one learns to avoid evil (akusala) and cultivate good (kusala). Other two important factors are shame and fear
of doing evil that strengthens the will not to repeat former errors nor create new ones.
In terms of practice, the above two (right effort, shame and fear) are encompassed in what is called repentance
(懺悔) that is part of the daily liturgical practice in Chinese Buddhism and it is also prominent in the Vajrasattva practice
of Vajrayana. There are also sutras about repentance, like the Repentance Sūtra in Response to Śāriputra
While formal practice helps reminding and indoctrinating ourselves the correct view, it is at the actual arising of an unwholesome intention when we can actually learn to let go of bad habits and stop repeating past mistakes. That is, purification doesn't mean that attachments are magically removed but through maintaining the right attitude one becomes mindful of good and bad thoughts. Seeing how wrong ideas lead to pain and suffering one can put an end to following and acting on them. This is purification on the relative level that brings about merit. The absolute purification is the complete practice of the Dharma whereby one attains liberation from samsara, and neither bad nor good thoughts are attached to."Ordinary people are stupid and only know they should repent for their past licentiousness—they do not know they should feel remorse for future errors. Because they do not have such remorse, their previous licentiousness is not extinguished and future errors continue to be generated. With previous licentiousness not extinguished and future errors continuing to be generated, how can this be called repentance?"
(Platform Sutra, ch. 6, tr. McRae)