Allah commands His Prophet Muhammad ,
﴿قُل لِلَّذِينَ كَفَرُواْ إِن يَنتَهُواْ﴾
(Say to those who have disbelieved, if they cease...) the disbelief, defiance and stubbornness they indulge in, and embrace Islam, obedience and repentance.
﴿يُغْفَرْ لَهُمْ مَّا قَدْ سَلَفَ﴾
(their past will be forgiven.) along with their sins and errors. It is recorded in the Sahih Al-Bukhari that Abu Wa'il said that Ibn Mas'ud said that the Messenger of Allah said,
«مَنْ أَحْسَنَ فِي الْإِسْلَامِ لَمْ يُؤَاخَذْ بِمَا عَمِلَ فِي الْجَاهِلِيَّةِ، وَمَنْ أَسَاءَ فِي الْإِسْلَامِ أُخِذَ بِالْأَوَّلِ وَالْآخِر»
(He who becomes good in his Islam, will not be punished for what he has committed during Jahiliyyah (before Islam). He who becomes bad in his Islam, will face a punishment for his previous and latter deeds.)
It is also recorded in the Sahih that the Messenger of Allah said,
«الْإِسْلَامُ يَجُبُّ مَا قَبْلَهُ وَالتَّوْبَةُ تَجُبُّ مَا كَانَ قَبْلَهَا»
("Islam erases what occurred before it, and repentance erases what occurs before it.'')
(But if they return, ) and remain on their ways,
﴿فَقَدْ مَضَتْ سُنَّتُ الاٌّوَّلِينِ﴾
(then the examples of those (punished) before them have already preceded.) ﴿8:38﴾ meaning, Our way with the nations of old is that when they disbelieve and rebel, We send down to them immediate torment and punishment.