On the authority of his father that the Prophet ﷺ said: I swear by Allah that if Allah wills I shall swear on an oath and then consider something else to be better than it without making atonement for my oath and doing the thing that is better. Or he said (according to another version): But doing the thing that is better and making atonement for my oath.
أَنَّ النَّبِيَّ ﷺ قَالَ إِنِّي وَاللَّهِ إِنْ شَاءَ اللَّهُ لاَ أَحْلِفُ عَلَى يَمِينٍ فَأَرَى غَيْرَهَا خَيْرًا مِنْهَا إِلاَّ كَفَّرْتُ عَنْ يَمِينِي وَأَتَيْتُ الَّذِي هُوَ خَيْرٌ أَوْ قَالَ إِلاَّ أَتَيْتُ الَّذِي هُوَ خَيْرٌ وَكَفَّرْتُ يَمِينِي