If we commit a sin, is it mentioned in the Qur'an or the hadith that it will be forgiven? Are there any conditions? Would they forgiven only if done in ignorance? What if we commit intentionally? Do we know for sure that our sin has been forgiven?
Always always remember that Allah is the most merciful and will always forgive your sins no matter how big they are as long as you repent to him sincerely and regret the sin and resolve not to do it again. You will always be forgiven as long as you're still alive and the sun did not rise from the west.
Say, "O My servants who have transgressed against themselves [by sinning], do not despair of the mercy of Allah . Indeed, Allah forgives all sins. Indeed, it is He who is the Forgiving, the Merciful." Quran 39:53
Repent sincerely and truly regret the sin and resolve not to go back to it and do good deeds and keep Allah in your heart. Remember Allah he is the most merciful and he forgives and NO SIN is greater than Allah's mercy. We all make mistakes and we will keep on making mistakes till the day we die but the best of us are the ones who when they make a mistake they turn to Allah sincerely and ask for his forgiveness.
On the authority of Anas (may Allah be pleased with him), who said: I heard the Messenger of Allah (ﷺ) say: Allah the Almighty said: O son of Adam, so long as you call upon Me and ask of Me, I shall forgive you for what you have done, and I shall not mind. O son of Adam, were your sins to reach the clouds of the sky and were you then to ask forgiveness of Me, I would forgive you. O son of Adam, were you to come to Me with sins nearly as great as the earth and were you then to face Me, ascribing no partner to Me, I would bring you forgiveness nearly as great as it. [Tirmidhi]
Know that Allah smiles and if you feel hopeless then ask yourself, how can we lose hope from a lord who smiles? Never despair of Allah's mercy.
(I heard it from a video and the guy said "how can we lose good from a lord who smiles" and I thought it would fit to say that here and change the good into hope)
And Allah knows best.