Narrated 'Abdur-Rahman bin Samura (RA):
Allah's Messenger (ﷺ) said: "When you swear an oath and then consider something else to be better than it, make atonement for your oath and do the thing that is better." [Agreed upon]. A wording of al-Bukhari has: "Do the thing that is better and make atonement for your oath."In a narration by Abu Dawud: "Make atonement for your oath, then do the thing that is better." [The chains of narrators of both Ahadith are Sahih (authentic)].
Reference: Bulugh al-Maram 1377
In-book reference: Book 13, Hadith 4
English translation: Book 13, Hadith 1377