صحيح البخاري Sahih Bukhari كتاب مناقب الأنصار The Merits of Al-Ansar
بَابُ قَوْلِ النَّبِيِّ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ: «لَوْلاَ الْهِجْرَةُ لَكُنْتُ مِنَ الأَنْصَارِ»:

(2) Chapter. The Statement of the Prophet: “But for the emigration, I would have been one of the Ansar.”

1 hadith
Hadith 3779
حَدَّثَنِي مُحَمَّدُ بْنُ بَشَّارٍ ، حَدَّثَنَا غُنْدَرٌ ، حَدَّثَنَا شُعْبَةُ ، عَنْ مُحَمَّدِ بْنِ زِيَادٍ ، عَنْ أَبِي هُرَيْرَةَ رَضِيَ اللَّهُ عَنْهُ ، عَنِ النَّبِيِّ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ ، أَوْ قَالَ أَبُو الْقَاسِمِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ : " لَوْ أَنَّ الْأَنْصَارَ سَلَكُوا وَادِيًا أَوْ شِعْبًا لَسَلَكْتُ فِي وَادِي الْأَنْصَارِ , وَلَوْلَا الْهِجْرَةُ لَكُنْتُ امْرَأً مِنْ الْأَنْصَارِ " ، فَقَالَ أَبُو هُرَيْرَةَ : مَا ظَلَمَ بِأَبِي وَأُمِّي آوَوْهُ وَنَصَرُوهُ , أَوْ كَلِمَةً أُخْرَى .
Narrated Abu Huraira: The Prophet or Abul-Qasim said, "If the Ansar took their way through a valley or a mountain pass, I would take Ansar's valley. And but for the migration, I would have been one of the Ansar." Abu Huraira used to say, "The Prophet is not unjust (by saying so). May my parents be sacrificed for him, for the Ansar sheltered and helped him," or said a similar sentence.
Hadith Reference Sahih Bukhari / The Merits of Al-Ansar / Hadith: 3779
Hadith Grading محدثین: أحاديث صحيح البخاريّ كلّها صحيحة