Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:41:34

And not equal are the good deed and the bad. Repel ˹evil˺ by that ˹deed˺ which is better; and thereupon the one whom between you and him is enmity ˹will become˺ as though he was a devoted friend.  

And they are not equal, the good deed and the evil deed, ˹even˺ with respect to their subdivisions, because any number of such ˹good deeds˺ are ˹always˺ above any number of the latter. Repel, the evil deed, with that, in other words, with that trait, which is better, such as ˹repelling˺ anger with endurance, ignorance with forbearance, and ˹the intention to inflict˺ harm with pardon, then, behold, he between whom and you there was enmity will be as though he were a dear friend, in other words, then your enemy will become like a close friend in terms of ˹his˺ affection ˹for you˺, if you act in such a way (alladhī, ‘he … whom’, is the subject; ka-annahu, ‘as though’, is the predicate; idhā is an adverbial particle for ˹expressing˺ the comparative import).
القرآن:٤١:٣٤

وَلَا تَسْتَوِي الْحَسَنَةُ وَلَا السَّيِّئَةُ ۚ ادْفَعْ بِالَّتِي هِيَ أَحْسَنُ فَإِذَا الَّذِي بَيْنَكَ وَبَيْنَهُ عَدَاوَةٌ كَأَنَّهُ وَلِيٌّ حَمِيمٌ  

{ولا تستوي الحسنة ولا السيئة} في جزئياتهما بعضهما فوق بعض {ادفع} السيئة {بالتي} أي بالخصلة التي {هي أحسن} كالغضب بالصبر والجهل بالحلم والإساءة بالعفو {فإذا الذي بينك وبينه عداوة كأنه ولي حميم} أي فيصير عدوك كالصديق القريب في محبته إذا فعلت ذلك فالذي مبتدأ وكأنه الخبر وإذا ظرف لمعنى التشبيه.