The Prophet ﷺ said, "I saw in a dream that I was migrating from Mecca to a land with date palms. My mind first thought it was Yamamah or Hajar, but it turned out to be Madinah, Yathrib. In this same dream I saw myself brandishing a sword, and its blade broke off. That turned out to represent the believers who were struck down on the day of Uhud. Then I brandished it again and it became better than ever, which turned out to represent the victory Allah brought afterward and the gathering of the believers. I also saw cattle in the dream, and Allah is good. They turned out to be the group of believers killed on the day of Uhud, while the good was what Allah brought of goodness afterward and the reward for the truthfulness Allah granted us on the day of Badr."
حدثنا محمود بن غيلان حدثنا أبو أسامة حدثنا بريدة عن أبي بردة
عن النبي ﷺ قال رأيت في المنام أني أهاجر من مكة إلى أرض بها نخل فذهب وهلي إلى أنها يمامة أو هجر فإذا هي المدينة يثرب ورأيت في رؤياي هذه أني هززت سيفا فانقطع صدره فإذا هو ما أصيب من المؤمنين يوم أحد ثم هززته فعاد أحسن ما كان فإذا هو ما جاء الله به من الفتح واجتماع المؤمنين ورأيت فيها أيضا بقرا والله خير فإذا هم النفر من المؤمنين يوم أحد وإذا الخير ما جاء الله به من الخير بعد وثواب الصدق الذي آتانا الله به يوم بدر
Bukhari narrated it in the chapter on the Virtues, in the section on the signs of prophethood in Islam, 3622/4081, 3987, 7041, 7035, and Muslim in the chapter on Dreams, in the section on the dream of the Prophet, 2272, from the hadith of Abu Usama, with this wording.