Abu Musa Ashari reported,

I came to the Prophet ﷺ with a group of the Asharis asking him to provide us with mounts. He said, "By Allah, I cannot give you mounts, and I have nothing to mount you on."We waited as long as Allah willed, then some camels were brought to him, and he ordered that we be given three fine camels with white humps. When we set off, we said to one another, "Allah will not bless this for us. We came to the Messenger of Allah ﷺ asking him for mounts, and he swore he would not give us any, then he gave us mounts."So they went back to him and told him this. He said, "It was not I who gave you the mounts, rather it was Allah who provided them. By Allah, if Allah wills, I never swear an oath and then see something better than it without making expiation for my oath and doing what is better."

Muslim 4263

Sahih

حدثنا خلف بن هشام وقتيبة بن سعيد ويحيى بن حبيب الحارثي واللفظ لخلف قالوا حدثنا حماد بن زيد عن غيلان بن جرير عن أبي بردة

عن أبي موسى الأشعري قال

أتيت النبي ﷺ في رهط من الأشعريين نستحمله فقال والله لا أحملكم وما عندي ما أحملكم عليه قال فلبثنا ما شاء الله ثم أتي بإبل فأمر لنا بثلاث ذود غر الذرى فلما انطلقنا قلنا أو قال بعضنا لبعض لا يبارك الله لنا أتينا رسول الله ﷺ نستحمله فحلف أن لا يحملنا ثم حملنا فأتوه فأخبروه فقال ما أنا حملتكم ولكن الله حملكم وإني والله إن شاء الله لا أحلف على يمين ثم أرى خيرا منها إلا كفرت عن يميني وأتيت الذي هو خير

مسلم 4263صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Muslim
Book
Oaths
Chapter
Recommendation for one who swore an oath then saw something better to do what is better and expiate for his oath
Numbering
Darussalam 4263
Muslim 4263