The Prophet ﷺ said to me, "Abdul-Rahman bin Samura, if you swear an oath and then see that something else is better than it, do the one that is better and offer expiation for your oath."
حدثنا محمد بن الصباح البزاز حدثنا هشيم أخبرنا يونس ومنصور يعني ابن زاذان عن الحسن
قال لي النبي ﷺ يا عبد الرحمن بن سمرة إذا حلفت على يمين فرأيت غيرها خيرا منها فأت الذي هو خير وكفر يمينك
Muslim narrated it in the Book of Oaths, chapter "The recommendation for one who swears an oath and then sees something better than it..." etc., hadith no. 1652, from the hadith of Hushaym. Bukhari narrated it in the Book of Expiations for Oaths, chapter "Expiation before and after breaking the oath," hadith no. 6722, from the hadith of Yunus and Mansur through him.